From 317c6b77f3ec1f077014149c57d6b13f58083969 Mon Sep 17 00:00:00 2001
From: Giovanni Campagna <gcampagna@src.gnome.org>
Date: Tue, 19 Jun 2012 23:32:45 +0200
Subject: [PATCH] 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
---
 js/misc/util.js | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/js/misc/util.js b/js/misc/util.js
index 8839ed6f8..7d36676ee 100644
--- a/js/misc/util.js
+++ b/js/misc/util.js
@@ -89,18 +89,22 @@ 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;
         }
-
-        throw err;
     }
     // Dummy child watch; we don't want to double-fork internally
     // because then we lose the parent-child relationship, which