Util: update trySpawn to new gjs GError mapping
Error rewriting code used an old version of the gjs GError support, and set a readonly .message property. https://bugzilla.gnome.org/show_bug.cgi?id=678502
This commit is contained in:
parent
e5f5a2adaa
commit
317c6b77f3
@ -89,19 +89,23 @@ function trySpawn(argv)
|
||||
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
||||
null, null);
|
||||
} catch (err) {
|
||||
if (err.code == GLib.SpawnError.G_SPAWN_ERROR_NOENT) {
|
||||
err.message = _("Command not found");
|
||||
} else {
|
||||
/* Rewrite the error in case of ENOENT */
|
||||
if (err.matches(GLib.SpawnError, GLib.SpawnError.NOENT)) {
|
||||
throw new GLib.SpawnError({ code: GLib.SpawnError.NOENT,
|
||||
message: _("Command not found") });
|
||||
} else if (err instanceof GLib.Error) {
|
||||
// The exception from gjs contains an error string like:
|
||||
// Error invoking GLib.spawn_command_line_async: Failed to
|
||||
// execute child process "foo" (No such file or directory)
|
||||
// We are only interested in the part in the parentheses. (And
|
||||
// we can't pattern match the text, since it gets localized.)
|
||||
err.message = err.message.replace(/.*\((.+)\)/, '$1');
|
||||
}
|
||||
|
||||
let message = err.message.replace(/.*\((.+)\)/, '$1');
|
||||
throw new (err.constructor)({ code: err.code,
|
||||
message: message });
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
// Dummy child watch; we don't want to double-fork internally
|
||||
// because then we lose the parent-child relationship, which
|
||||
// can break polkit. See https://bugzilla.redhat.com//show_bug.cgi?id=819275
|
||||
|
Loading…
Reference in New Issue
Block a user