[gnome-documents/gnome-3-28] application: Tie the catch block more tightly to the failure site



commit 958de376c74c4071e8df0df6ef8ecbea2121f299
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Dec 8 17:13:52 2017 +0100

    application: Tie the catch block more tightly to the failure site
    
    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=791518

 src/application.js | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 3de397ac..8d168588 100644
--- a/src/application.js
+++ b/src/application.js
@@ -153,19 +153,21 @@ var Application = new Lang.Class({
                 function(object, res) {
                     try {
                         let info = object.query_info_finish(res);
-                        this.gettingStartedLocation = file.get_parent();
-
-                        manager.index_file_async(file, null,
-                            function(object, res) {
-                                try {
-                                    manager.index_file_finish(res);
-                                } catch (e) {
-                                    logError(e, 'Error indexing the getting started PDF');
-                                }
-                            });
                     } catch (e) {
                         checkNextFile.apply(this);
+                        return;
                     }
+
+                    this.gettingStartedLocation = file.get_parent();
+
+                    manager.index_file_async(file, null,
+                        function(object, res) {
+                            try {
+                                manager.index_file_finish(res);
+                            } catch (e) {
+                                logError(e, 'Error indexing the getting started PDF');
+                            }
+                        });
                 }));
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]