Improve console output
The console
methods should help to figure out what the object being logged is.
I identified the following issues so far
- In some cases it crashes
- Prints an empty object for GObject
- Does not print the error message of GError
log
and logError
are good at this, but we will need console
to get better to replace log
and logError
with it – see #502 (closed)
# actual
gjs> console.log(imports.gi.Gio)
resource:///org/gnome/gjs/modules/esm/console.js:66:17 uncaught exception: Object
...
# expected ~
gjs> console.log(imports.gi.Gio)
Gjs-Console-Message: 21:10:12.956: [object GIRepositoryNamespace Gio]
# log actual
gjs> log(imports.gi.Gio)
Gjs-Message: 21:09:23.031: JS LOG: [object GIRepositoryNamespace]
# actual
gjs> console.log(imports.gi.GLib)resource:///org/gnome/gjs/modules/esm/console.js:66:17 Error: Unions must currently be registered as boxed types
...
# expected ~
gjs> console.log(imports.gi.GLib)
Gjs-Console-Message: 21:10:12.956: [object GIRepositoryNamespace GLib]
# log actual
gjs> log(imports.gi.GLib)
Gjs-Message: 21:09:23.031: JS LOG: [object GIRepositoryNamespace]
# actual
gjs> console.log(new imports.gi.GObject.Object())
Gjs-Console-Message: 21:12:05.247: {}
# expected ~
gjs> console.log(new imports.gi.GObject.Object())
Gjs-Console-Message: 21:10:12.956: [object GType:GLocalFile] {
// listing GObject properties would be nice
...
}
# log
gjs> log(new imports.gi.GObject.Object())
Gjs-Message: 21:31:42.128: JS LOG: [object instance wrapper GIName:GObject.Object jsobj@0x240c0f5fc80 native@0x55f2c9eccb60]
# actual
gjs> try {imports.gi.Gio.File.new_for_path('/foo').load_contents(null) } catch (err) { console.error(err) }
(gjs:68852): Gjs-Console-CRITICAL **: 21:22:41.833: {
"stack": "@typein:7:47\n@<stdin>:1:42\n",
"fileName": "typein",
"lineNumber": 7,
"columnNumber": 47
}
# expected ~
gjs> try {imports.gi.Gio.File.new_for_path('/foo').load_contents(null) } catch (err) { console.error(err) }
(gjs:68852): Gjs-Console-CRITICAL **: 21:22:41.833: Gio.IOErrorEnum: Error opening file /foo: No such file or directory
@typein:9:47
@<stdin>:1:42
# logError
gjs> try {imports.gi.Gio.File.new_for_path('/foo').load_contents(null) } catch (err) { logError(err) }
(gjs:68852): Gjs-WARNING **: 21:24:00.392: JS ERROR: Gio.IOErrorEnum: Error opening file /foo: No such file or directory
@typein:9:47
@<stdin>:1:42
# actual
gjs> console.log(new TextDecoder())
Gjs-Console-Message: 21:38:35.467: {
"encoding": "utf-8",
"ignoreBOM": false,
"fatal": false
}
# expected
gjs> console.log(new TextDecoder())
Gjs-Console-Message: 21:38:35.467: TextDecoder {
"encoding": "utf-8",
"ignoreBOM": false,
"fatal": false
}
# log
gjs> log(new TextDecoder())
Gjs-Message: 21:38:32.520: JS LOG: { encoding: "utf-8", ignoreBOM: false, fatal: false }
# Node.js
> console.log(new TextDecoder())
TextDecoder { encoding: 'utf-8', fatal: false, ignoreBOM: false }
Edited by Sonny Piers