Skip to content
This repository has been archived by the owner on Oct 24, 2018. It is now read-only.

Commit

Permalink
better error handling, fix #103
Browse files Browse the repository at this point in the history
  • Loading branch information
guinux committed Mar 1, 2016
1 parent 07ee570 commit 7266a57
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/common.vala
Expand Up @@ -32,11 +32,11 @@ namespace Pamac {
}

public struct ErrorInfos {
public uint errno;
public string message;
public string[] details;
public ErrorInfos () {
message = "";
details = {};
}
}
}
33 changes: 23 additions & 10 deletions src/daemon.vala
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -782,8 +796,7 @@ namespace Pamac {
}
} else {
current_error = ErrorInfos () {
message = _("Authentication failed"),
details = {}
message = _("Authentication failed")
};
trans_release ();
refresh_handle ();
Expand Down
7 changes: 6 additions & 1 deletion src/manager_window.vala
Expand Up @@ -1738,7 +1738,12 @@ namespace Pamac {
}

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 ();
transaction.to_load.remove_all ();
if (refreshing) {
Expand Down
10 changes: 6 additions & 4 deletions src/transaction.vala
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 7266a57

Please sign in to comment.