better error handling, fix #103

This commit is contained in:
guinux 2016-03-01 15:43:51 +01:00
parent 07ee57015b
commit 7266a57664
4 changed files with 36 additions and 16 deletions

View File

@ -32,11 +32,11 @@ namespace Pamac {
} }
public struct ErrorInfos { public struct ErrorInfos {
public uint errno;
public string message; public string message;
public string[] details; public string[] details;
public ErrorInfos () { public ErrorInfos () {
message = ""; message = "";
details = {};
} }
} }
} }

View File

@ -134,8 +134,7 @@ namespace Pamac {
alpm_config.set_handle (); alpm_config.set_handle ();
if (alpm_config.handle == null) { if (alpm_config.handle == null) {
current_error = ErrorInfos () { current_error = ErrorInfos () {
message = _("Failed to initialize alpm library"), message = _("Failed to initialize alpm library")
details = {}
}; };
trans_commit_finished (false); trans_commit_finished (false);
} else { } else {
@ -347,8 +346,10 @@ namespace Pamac {
// We should always succeed if at least one DB was upgraded - we may possibly // We should always succeed if at least one DB was upgraded - we may possibly
// fail later with unresolved deps, but that should be rare, and would be expected // fail later with unresolved deps, but that should be rare, and would be expected
if (success == 0) { if (success == 0) {
Alpm.Errno errno = alpm_config.handle.errno ();
current_error.errno = (uint) errno;
current_error.message = _("Failed to synchronize any databases"); current_error.message = _("Failed to synchronize any databases");
current_error.details = { Alpm.strerror (alpm_config.handle.errno ()) }; current_error.details = { Alpm.strerror (errno) };
refresh_finished (false); refresh_finished (false);
} else { } else {
refresh_finished (true); refresh_finished (true);
@ -465,8 +466,10 @@ namespace Pamac {
current_error = ErrorInfos (); current_error = ErrorInfos ();
cancellable.reset (); cancellable.reset ();
if (alpm_config.handle.trans_init (transflags) == -1) { if (alpm_config.handle.trans_init (transflags) == -1) {
Alpm.Errno errno = alpm_config.handle.errno ();
current_error.errno = (uint) errno;
current_error.message = _("Failed to init transaction"); current_error.message = _("Failed to init transaction");
current_error.details = { Alpm.strerror (alpm_config.handle.errno ()) }; current_error.details = { Alpm.strerror (errno) };
return false; return false;
} else { } else {
intern_lock = true; intern_lock = true;
@ -477,8 +480,10 @@ namespace Pamac {
public bool trans_sysupgrade (bool enable_downgrade) { public bool trans_sysupgrade (bool enable_downgrade) {
current_error = ErrorInfos (); current_error = ErrorInfos ();
if (alpm_config.handle.trans_sysupgrade ((enable_downgrade) ? 1 : 0) == -1) { if (alpm_config.handle.trans_sysupgrade ((enable_downgrade) ? 1 : 0) == -1) {
Alpm.Errno errno = alpm_config.handle.errno ();
current_error.errno = (uint) errno;
current_error.message = _("Failed to prepare transaction"); current_error.message = _("Failed to prepare transaction");
current_error.details = { Alpm.strerror (alpm_config.handle.errno ()) }; current_error.details = { Alpm.strerror (errno) };
return false; return false;
} }
return true; return true;
@ -492,6 +497,7 @@ namespace Pamac {
// just skip duplicate or ignored targets // just skip duplicate or ignored targets
return true; return true;
} else { } else {
current_error.errno = (uint) errno;
current_error.message = _("Failed to prepare transaction"); current_error.message = _("Failed to prepare transaction");
current_error.details = { "%s: %s".printf (pkg.name, Alpm.strerror (errno)) }; current_error.details = { "%s: %s".printf (pkg.name, Alpm.strerror (errno)) };
return false; return false;
@ -569,12 +575,16 @@ namespace Pamac {
current_error = ErrorInfos (); current_error = ErrorInfos ();
Alpm.Package* pkg = alpm_config.handle.load_file (pkgpath, 1, alpm_config.handle.localfilesiglevel); Alpm.Package* pkg = alpm_config.handle.load_file (pkgpath, 1, alpm_config.handle.localfilesiglevel);
if (pkg == null) { if (pkg == null) {
Alpm.Errno errno = alpm_config.handle.errno ();
current_error.errno = (uint) errno;
current_error.message = _("Failed to prepare transaction"); current_error.message = _("Failed to prepare transaction");
current_error.details = { "%s: %s".printf (pkgpath, Alpm.strerror (alpm_config.handle.errno ())) }; current_error.details = { "%s: %s".printf (pkgpath, Alpm.strerror (errno)) };
return false; return false;
} else if (alpm_config.handle.trans_add_pkg (pkg) == -1) { } else if (alpm_config.handle.trans_add_pkg (pkg) == -1) {
Alpm.Errno errno = alpm_config.handle.errno ();
current_error.errno = (uint) errno;
current_error.message = _("Failed to prepare transaction"); current_error.message = _("Failed to prepare transaction");
current_error.details = { "%s: %s".printf (pkg->name, Alpm.strerror (alpm_config.handle.errno ())) }; current_error.details = { "%s: %s".printf (pkg->name, Alpm.strerror (errno)) };
// free the package because it will not be used // free the package because it will not be used
delete pkg; delete pkg;
return false; return false;
@ -590,8 +600,10 @@ namespace Pamac {
current_error.details = { _("target not found: %s").printf (pkgname) }; current_error.details = { _("target not found: %s").printf (pkgname) };
return false; return false;
} else if (alpm_config.handle.trans_remove_pkg (pkg) == -1) { } else if (alpm_config.handle.trans_remove_pkg (pkg) == -1) {
Alpm.Errno errno = alpm_config.handle.errno ();
current_error.errno = (uint) errno;
current_error.message = _("Failed to prepare transaction"); current_error.message = _("Failed to prepare transaction");
current_error.details = { "%s: %s".printf (pkg.name, Alpm.strerror (alpm_config.handle.errno ())) }; current_error.details = { "%s: %s".printf (pkg.name, Alpm.strerror (errno)) };
return false; return false;
} }
return true; return true;
@ -603,6 +615,7 @@ namespace Pamac {
Alpm.List<void*> err_data; Alpm.List<void*> err_data;
if (alpm_config.handle.trans_prepare (out err_data) == -1) { if (alpm_config.handle.trans_prepare (out err_data) == -1) {
Alpm.Errno errno = alpm_config.handle.errno (); Alpm.Errno errno = alpm_config.handle.errno ();
current_error.errno = (uint) errno;
current_error.message = _("Failed to prepare transaction"); current_error.message = _("Failed to prepare transaction");
string detail = Alpm.strerror (errno); string detail = Alpm.strerror (errno);
switch (errno) { switch (errno) {
@ -723,6 +736,7 @@ namespace Pamac {
trans_commit_finished (false); trans_commit_finished (false);
return; return;
} }
current_error.errno = (uint) errno;
current_error.message = _("Failed to commit transaction"); current_error.message = _("Failed to commit transaction");
string detail = Alpm.strerror (errno); string detail = Alpm.strerror (errno);
string[] details = {}; string[] details = {};
@ -782,8 +796,7 @@ namespace Pamac {
} }
} else { } else {
current_error = ErrorInfos () { current_error = ErrorInfos () {
message = _("Authentication failed"), message = _("Authentication failed")
details = {}
}; };
trans_release (); trans_release ();
refresh_handle (); refresh_handle ();

View File

@ -1738,7 +1738,12 @@ namespace Pamac {
} }
void on_transaction_finished (bool success) { void on_transaction_finished (bool success) {
set_buttons_sensitive (false); if (transaction.to_add.length == 0
&& transaction.to_remove.length == 0
&& transaction.to_load.length == 0
&& transaction.to_build.length == 0) {
set_buttons_sensitive (false);
}
refresh_packages_list (); refresh_packages_list ();
transaction.to_load.remove_all (); transaction.to_load.remove_all ();
if (refreshing) { if (refreshing) {

View File

@ -1122,7 +1122,9 @@ namespace Pamac {
} }
void handle_error (ErrorInfos error) { void handle_error (ErrorInfos error) {
if (error.message != null && error.message != "") { if (error.message != "") {
progress_dialog.action_label.set_text ("");
progress_dialog.progressbar.set_fraction (0);
progress_dialog.expander.set_expanded (true); progress_dialog.expander.set_expanded (true);
progress_dialog.spawn_in_term ({"echo", "-n", error.message}); progress_dialog.spawn_in_term ({"echo", "-n", error.message});
Gtk.TextIter start_iter; Gtk.TextIter start_iter;
@ -1152,7 +1154,6 @@ namespace Pamac {
transaction_info_dialog.textbuffer.get_start_iter (out start_iter); transaction_info_dialog.textbuffer.get_start_iter (out start_iter);
transaction_info_dialog.textbuffer.get_end_iter (out end_iter); transaction_info_dialog.textbuffer.get_end_iter (out end_iter);
transaction_info_dialog.textbuffer.delete (ref start_iter, ref end_iter); transaction_info_dialog.textbuffer.delete (ref start_iter, ref end_iter);
progress_dialog.progressbar.set_fraction (0);
progress_dialog.spawn_in_term ({"echo"}); progress_dialog.spawn_in_term ({"echo"});
while (Gtk.events_pending ()) { while (Gtk.events_pending ()) {
Gtk.main_iteration (); Gtk.main_iteration ();
@ -1277,9 +1278,10 @@ namespace Pamac {
} }
} }
} else { } else {
// if it is an authentication error, database was not modified // if it is an authentication or a download error, database was not modified
var err = get_current_error (); var err = get_current_error ();
if (err.message != dgettext (null, "Authentication failed")) { if (err.message != dgettext (null, "Authentication failed")
&& err.errno != Alpm.Errno.EXTERNAL_DOWNLOAD) {
clear_lists (); clear_lists ();
database_modified = true; database_modified = true;
} }