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 uint errno;
public string message;
public string[] details;
public ErrorInfos () {
message = "";
details = {};
}
}
}

View File

@ -134,8 +134,7 @@ namespace Pamac {
alpm_config.set_handle ();
if (alpm_config.handle == null) {
current_error = ErrorInfos () {
message = _("Failed to initialize alpm library"),
details = {}
message = _("Failed to initialize alpm library")
};
trans_commit_finished (false);
} else {
@ -347,8 +346,10 @@ namespace Pamac {
// 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
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.details = { Alpm.strerror (alpm_config.handle.errno ()) };
current_error.details = { Alpm.strerror (errno) };
refresh_finished (false);
} else {
refresh_finished (true);
@ -465,8 +466,10 @@ namespace Pamac {
current_error = ErrorInfos ();
cancellable.reset ();
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.details = { Alpm.strerror (alpm_config.handle.errno ()) };
current_error.details = { Alpm.strerror (errno) };
return false;
} else {
intern_lock = true;
@ -477,8 +480,10 @@ namespace Pamac {
public bool trans_sysupgrade (bool enable_downgrade) {
current_error = ErrorInfos ();
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.details = { Alpm.strerror (alpm_config.handle.errno ()) };
current_error.details = { Alpm.strerror (errno) };
return false;
}
return true;
@ -492,6 +497,7 @@ namespace Pamac {
// just skip duplicate or ignored targets
return true;
} else {
current_error.errno = (uint) errno;
current_error.message = _("Failed to prepare transaction");
current_error.details = { "%s: %s".printf (pkg.name, Alpm.strerror (errno)) };
return false;
@ -569,12 +575,16 @@ namespace Pamac {
current_error = ErrorInfos ();
Alpm.Package* pkg = alpm_config.handle.load_file (pkgpath, 1, alpm_config.handle.localfilesiglevel);
if (pkg == null) {
Alpm.Errno errno = alpm_config.handle.errno ();
current_error.errno = (uint) errno;
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;
} 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.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
delete pkg;
return false;
@ -590,8 +600,10 @@ namespace Pamac {
current_error.details = { _("target not found: %s").printf (pkgname) };
return false;
} 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.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 true;
@ -603,6 +615,7 @@ namespace Pamac {
Alpm.List<void*> err_data;
if (alpm_config.handle.trans_prepare (out err_data) == -1) {
Alpm.Errno errno = alpm_config.handle.errno ();
current_error.errno = (uint) errno;
current_error.message = _("Failed to prepare transaction");
string detail = Alpm.strerror (errno);
switch (errno) {
@ -723,6 +736,7 @@ namespace Pamac {
trans_commit_finished (false);
return;
}
current_error.errno = (uint) errno;
current_error.message = _("Failed to commit transaction");
string detail = Alpm.strerror (errno);
string[] details = {};
@ -782,8 +796,7 @@ namespace Pamac {
}
} else {
current_error = ErrorInfos () {
message = _("Authentication failed"),
details = {}
message = _("Authentication failed")
};
trans_release ();
refresh_handle ();

View File

@ -1738,7 +1738,12 @@ namespace Pamac {
}
void on_transaction_finished (bool success) {
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 ();
transaction.to_load.remove_all ();
if (refreshing) {

View File

@ -1122,7 +1122,9 @@ namespace Pamac {
}
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.spawn_in_term ({"echo", "-n", error.message});
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_end_iter (out 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"});
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
@ -1277,9 +1278,10 @@ namespace Pamac {
}
}
} 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 ();
if (err.message != dgettext (null, "Authentication failed")) {
if (err.message != dgettext (null, "Authentication failed")
&& err.errno != Alpm.Errno.EXTERNAL_DOWNLOAD) {
clear_lists ();
database_modified = true;
}