From eb51942a051f18f5993914968fcefb00a56c3625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 24 Mar 2020 07:44:31 +0100 Subject: [PATCH] screenshot: Return error when stream creation fails The Shell.Screenshot API expects valid output streams for writing the completed screenshot, not NULL. Handle this properly by returning an error instead of passing it on to the screenshot. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1123 --- js/ui/screenshot.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js index 09f5c5109..78afc4ae4 100644 --- a/js/ui/screenshot.js +++ b/js/ui/screenshot.js @@ -84,7 +84,7 @@ var ScreenshotService = class { } } - _createStream(filename) { + _createStream(filename, invocation) { if (filename == '') return [Gio.MemoryOutputStream.new_resizable(), null]; @@ -94,6 +94,7 @@ var ScreenshotService = class { let stream = file.replace(null, false, Gio.FileCreateFlags.NONE, null); return [stream, file]; } catch (e) { + invocation.return_value(GLib.Variant.new('(bs)', [false, ''])); return [null, null]; } } @@ -104,10 +105,11 @@ var ScreenshotService = class { return [stream, file]; } catch (e) { if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS)) - return [null, null]; + break; } } + invocation.return_value(GLib.Variant.new('(bs)', [false, ''])); return [null, null]; } @@ -169,7 +171,9 @@ var ScreenshotService = class { if (!screenshot) return; - let [stream, file] = this._createStream(filename); + let [stream, file] = this._createStream(filename, invocation); + if (!stream) + return; screenshot.screenshot_area(x, y, width, height, stream, (o, res) => { @@ -190,7 +194,9 @@ var ScreenshotService = class { if (!screenshot) return; - let [stream, file] = this._createStream(filename); + let [stream, file] = this._createStream(filename, invocation); + if (!stream) + return; screenshot.screenshot_window(includeFrame, includeCursor, stream, (o, res) => { @@ -211,7 +217,9 @@ var ScreenshotService = class { if (!screenshot) return; - let [stream, file] = this._createStream(filename); + let [stream, file] = this._createStream(filename, invocation); + if (!stream) + return; screenshot.screenshot(includeCursor, stream, (o, res) => {