[gnome-documents] documents: Tie the catch blocks more tightly to the failure sites
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] documents: Tie the catch blocks more tightly to the failure sites
- Date: Thu, 20 Apr 2017 17:51:16 +0000 (UTC)
commit 1db2a08a3bdbf47799aecca602c31e3d7a4e6b70
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Apr 5 15:50:37 2017 +0200
documents: Tie the catch blocks more tightly to the failure sites
Having a lot of code inside a try statement makes it harder to follow
the error handling logic. The catch statements are far away from the
code that can throw an exception, so it is difficult to match them
together. Let's reduce the size of the try blocks by only using them
for fallible operations.
https://bugzilla.gnome.org/show_bug.cgi?id=781532
src/documents.js | 50 +++++++++++++++++++++++++++++---------------------
1 files changed, 29 insertions(+), 21 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 525dd0a..4b20db7 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -564,34 +564,42 @@ const DocCommon = new Lang.Class({
thumbFile.read_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this,
function(object, res) {
- try {
- let stream = object.read_finish(res);
- let scale = Application.application.getScaleFactor();
- GdkPixbuf.Pixbuf.new_from_stream_at_scale_async(stream,
- Utils.getIconSize() * scale, Utils.getIconSize() * scale,
- true, null, Lang.bind(this,
- function(object, res) {
- try {
- let pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res);
- this._setOrigPixbuf(pixbuf);
- } catch (e) {
- if (!e.matches(GdkPixbuf.PixbufError,
GdkPixbuf.PixbufError.UNKNOWN_TYPE))
- logError(e, 'Unable to create pixbuf from ' + thumbFile.get_uri());
-
- this._failedThumbnailing = true;
- this._thumbPath = null;
- thumbFile.delete_async(GLib.PRIORITY_DEFAULT, null, null);
- }
+ let stream;
- // close the underlying stream immediately
- stream.close_async(0, null, null);
- }));
+ try {
+ stream = object.read_finish(res);
} catch (e) {
logError(e, 'Unable to read file at ' + thumbFile.get_uri());
this._failedThumbnailing = true;
this._thumbPath = null;
thumbFile.delete_async(GLib.PRIORITY_DEFAULT, null, null);
+ return;
}
+
+ let scale = Application.application.getScaleFactor();
+ GdkPixbuf.Pixbuf.new_from_stream_at_scale_async(stream,
+ Utils.getIconSize() * scale, Utils.getIconSize() * scale,
+ true, null, Lang.bind(this,
+ function(object, res) {
+ // close the underlying stream immediately
+ stream.close_async(0, null, null);
+
+ let pixbuf;
+
+ try {
+ pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res);
+ } catch (e) {
+ if (!e.matches(GdkPixbuf.PixbufError, GdkPixbuf.PixbufError.UNKNOWN_TYPE))
+ logError(e, 'Unable to create pixbuf from ' + thumbFile.get_uri());
+
+ this._failedThumbnailing = true;
+ this._thumbPath = null;
+ thumbFile.delete_async(GLib.PRIORITY_DEFAULT, null, null);
+ return;
+ }
+
+ this._setOrigPixbuf(pixbuf);
+ }));
}));
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]