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,18 +89,22 @@ function trySpawn(argv)
|
|||||||
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD,
|
||||||
null, null);
|
null, null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code == GLib.SpawnError.G_SPAWN_ERROR_NOENT) {
|
/* Rewrite the error in case of ENOENT */
|
||||||
err.message = _("Command not found");
|
if (err.matches(GLib.SpawnError, GLib.SpawnError.NOENT)) {
|
||||||
} else {
|
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:
|
// The exception from gjs contains an error string like:
|
||||||
// Error invoking GLib.spawn_command_line_async: Failed to
|
// Error invoking GLib.spawn_command_line_async: Failed to
|
||||||
// execute child process "foo" (No such file or directory)
|
// execute child process "foo" (No such file or directory)
|
||||||
// We are only interested in the part in the parentheses. (And
|
// We are only interested in the part in the parentheses. (And
|
||||||
// we can't pattern match the text, since it gets localized.)
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
// Dummy child watch; we don't want to double-fork internally
|
// Dummy child watch; we don't want to double-fork internally
|
||||||
// because then we lose the parent-child relationship, which
|
// because then we lose the parent-child relationship, which
|
||||||
|
Loading…
Reference in New Issue
Block a user