Package: tootle
Version: 0.2.0-1
Severity: minor
Tags: patch

Dear Maintainer,

When debugging an entirely unrelated problem (wait for it), I got annoyed at 
the 
compiler warnings and wrote some code to deal with all 20 of them.

There's 4 main types of warnings this patch will fix: 
1) Asynchronous calls that were being invoked in an obsolete way - they were 
implicitly invoking
'begin', made this call explicit
2) Some code was throwing exceptions (at least as far as the compiler was 
concerned), and was not catching
it.  Wrote some exception try/catch blocks to catch them.  Was kind of strict 
in terms of erroring
out instead of warning when this happened - if it turns out these exceptions 
come out in practice, though
the scope of the exceptions and whether or not they are error/warnings would be 
the first thing to check.
So far I haven't triggered them.
3) Some code would never be executed, as it  occurs after the program is shut 
down.  Removed it.
4) (probably the most contentious) some code was using obsolete APIs, changed 
or removed it.

Previously:

../../src/Widgets/ImageToggleButton.vala:18.9-18.26: warning: 
Gtk.Button.set_focus_on_click has been deprecated since 3.20
../../src/Html.vala:4.24-4.74: warning: unhandled error `GLib.RegexError'
        var all_tags = new Regex("<(.|\n)*?>", RegexCompileFlags.CASELESS);
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../src/Html.vala:5.16-5.51: warning: unhandled error `GLib.RegexError'
        return all_tags.replace(content, -1, 0, "");
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../src/Html.vala:16.27-16.98: warning: unhandled error `GLib.RegexError'
        var html_params = new Regex("(class|target|rel)=\"(.|\n)*?\"", 
RegexCompileFlags.CASELESS);
                          
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../src/Html.vala:17.26-17.64: warning: unhandled error `GLib.RegexError'
        var simplified = html_params.replace(divided, -1, 0, "");
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../src/Notificator.vala:118.9-118.45: warning: unhandled error `GLib.Error'
        parser.load_from_data (sanitized, -1);
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../src/Notificator.vala:85.9-85.39: warning: unhandled error `GLib.Error'
        parser.load_from_data (msg, -1);
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../src/Notificator.vala:63.9-63.13: warning: implicit .begin is deprecated
../../src/Watchlist.vala:98.13-98.29: warning: implicit .begin is deprecated
../../src/InstanceAccount.vala:36.9-36.25: warning: implicit .begin is 
deprecated
../../src/ImageCache.vala:120.30-120.91: warning: unhandled error `GLib.Error'
                var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, 
size, true);
                             
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../src/Network.vala:129.26-129.87: warning: unhandled error `GLib.Error'
            var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, 
size, true);
                         
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../src/Views/TimelineView.vala:175.9-175.25: warning: implicit .begin is 
deprecated
../../src/Dialogs/NewAccountDialog.vala:128.24-128.42: warning: unhandled error 
`GLib.Error'
            var root = network.parse (msg);
                       ^^^^^^^^^^^^^^^^^^^
../../src/Network.vala:150.26-150.60: warning: unhandled error `GLib.Error'
            var pixbuf = new Gdk.Pixbuf.from_stream (stream);
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../src/Network.vala:171.26-171.87: warning: unhandled error `GLib.Error'
            var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, 
size, true);
                         
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../src/Widgets/AttachmentWidget.vala:95.28-95.47: warning: unhandled error 
`GLib.Error'
                var root = network.parse (mess);
                           ^^^^^^^^^^^^^^^^^^^^
../../src/Dialogs/PostDialog.vala:40.23-40.37: warning: 
Gtk.Dialog.get_action_area has been deprecated since 3.12
../../src/Dialogs/PostDialog.vala:42.9-42.23: warning: 
Gtk.Dialog.get_action_area has been deprecated since 3.12
../../src/Widgets/AttachmentWidget.vala:105.13-105.98: warning: unreachable 
code detected
            app.error (_("File read error"), _("Can't read file %s: %s").printf 
(uri, e.message));
            
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation succeeded - 20 warning(s)

Now: there's no more warnings.

This is my first hand at vala, so hopefully this helps and is sensible...

Jeff Cliff

-- System Information:
Debian Release: buster/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 4.18.0-2-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_CA:en (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages tootle depends on:
ii  dconf-gsettings-backend [gsettings-backend]  0.30.1-1
ii  elementary-xfce-icon-theme                   0.13.1-1
ii  libc6                                        2.27-8
ii  libgdk-pixbuf2.0-0                           2.38.0+dfsg-6
ii  libgee-0.8-2                                 0.20.1-1
ii  libglib2.0-0                                 2.58.1-2
ii  libgranite5                                  5.2.1-1
ii  libgtk-3-0                                   3.24.1-2
ii  libjson-glib-1.0-0                           1.4.4-1
ii  libsoup2.4-1                                 2.64.1-3

tootle recommends no packages.

tootle suggests no packages.

-- no debconf information
catches exceptions and deal with compiler warnings
--- a/src/Dialogs/NewAccountDialog.vala
+++ b/src/Dialogs/NewAccountDialog.vala
@@ -125,11 +125,18 @@
             grid.sensitive = true;
             if (show_error (msg)) return;
             
-            var root = network.parse (msg);
+            try {
+           var root = network.parse (msg);
+           
             var id = root.get_string_member ("client_id");
             var secret = root.get_string_member ("client_secret");
             client_id = id;
             client_secret = secret;
+           }
+            catch (GLib.Error e) {
+           // seems like it would be better to print soup.message here
+                error ("network parse error");
+            }
             
             info ("Received tokens from %s", instance);
             request_auth_code ();
--- a/src/Dialogs/PostDialog.vala
+++ b/src/Dialogs/PostDialog.vala
@@ -37,9 +37,11 @@
         if (redrafting != null)
             visibility_opt = redrafting.visibility;
         
-        var actions = get_action_area ().get_parent () as Gtk.Box;
+        //var actions = get_action_area ().get_parent () as Gtk.Box;
+       
+       
         var content = get_content_area ();
-        get_action_area ().hexpand = false;
+        //get_action_area ().hexpand = false;
         
         visibility = get_visibility_btn ();
         visibility.tooltip_text = _("Post Visibility");
@@ -108,10 +110,11 @@
         attachments = new AttachmentBox (true);
         counter = new Label ("");
         
-        actions.pack_start (counter, false, false, 6);
-        actions.pack_end (spoiler, false, false, 6);
-        actions.pack_end (visibility, false, false, 0);
-        actions.pack_end (attach, false, false, 6);
+        //actions.pack_start (counter, false, false, 6);
+        //actions.pack_end (spoiler, false, false, 6);
+        //actions.pack_end (visibility, false, false, 0);
+        //actions.pack_end (attach, false, false, 6);
+
         content.pack_start (spoiler_revealer, false, false, 6);
         content.pack_start (scroll, false, false, 6);
         content.pack_start (attachments, false, false, 6);
--- a/src/Html.vala
+++ b/src/Html.vala
@@ -1,8 +1,14 @@
 public class Tootle.Html {
 
     public static string remove_tags (string content) {
-        var all_tags = new Regex("<(.|\n)*?>", RegexCompileFlags.CASELESS);
+    try {
+       var all_tags = new Regex("<(.|\n)*?>", RegexCompileFlags.CASELESS);
         return all_tags.replace(content, -1, 0, "");
+       }
+     catch (GLib.RegexError  e)
+     {
+           error (e.message);
+     }
     }
 
     public static string simplify (string content) {      
@@ -12,7 +18,9 @@
         .replace("<br />", "\n")
         .replace("<p>", "")
         .replace("</p>", "\n\n");
-        
+
+  try
+  {
         var html_params = new Regex("(class|target|rel)=\"(.|\n)*?\"", 
RegexCompileFlags.CASELESS);
         var simplified = html_params.replace(divided, -1, 0, "");
         
@@ -20,6 +28,11 @@
             simplified = simplified.slice (0, simplified.last_index_of ("\n"));
         
         return simplified;
+       }
+     catch (GLib.RegexError  e)
+     {
+           error (e.message);
+     }
     }
 
     public static string uri_encode (string content) {
--- a/src/ImageCache.vala
+++ b/src/ImageCache.vala
@@ -117,9 +117,16 @@
                 debug("Caching %s@%d", uri, size);
                 var data = msg.response_body.data;
                 var stream = new MemoryInputStream.from_data (data);
-                var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, 
size, size, true);
+       try {
+               var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, 
size, true);
                 store_pixbuf(ci, pixbuf);
                 cb(pixbuf);
+           }
+          catch (GLib.Error  e)
+          {
+              error (e.message);
+         }
+        
                 msg.disconnect(id);
             });
             in_progress[ci] = msg;
--- a/src/InstanceAccount.vala
+++ b/src/InstanceAccount.vala
@@ -33,7 +33,7 @@
         notificator.status_added.connect (status_added);
         notificator.status_removed.connect (status_removed);
         notificator.notification.connect (notification);
-        notificator.start ();
+        notificator.start.begin();
     }
     
     public bool is_current () {
--- a/src/Network.vala
+++ b/src/Network.vala
@@ -126,8 +126,19 @@
             
             var data = msg.response_body.data;
             var stream = new MemoryInputStream.from_data (data);
-            var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, 
size, true);
+           try {
+           var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, 
size, true);
             avatar.pixbuf = pixbuf.scale_simple (size, size, 
Gdk.InterpType.BILINEAR);
+                       }
+            catch (GLib.RegexError  e)
+            {
+            error (e.message);
+            }
+            catch (GLib.Error  e)
+            {
+            error (e.message);
+            }
+
         });
         network.queue_custom (msg);
     }
@@ -147,8 +158,18 @@
             
             var data = msg.response_body.data;
             var stream = new MemoryInputStream.from_data (data);
-            var pixbuf = new Gdk.Pixbuf.from_stream (stream);
-            image.set_from_pixbuf (pixbuf);
+           try {
+               var pixbuf = new Gdk.Pixbuf.from_stream (stream);
+                image.set_from_pixbuf (pixbuf);
+          }
+            catch (GLib.RegexError  e)
+           {
+               error (e.message);
+           }
+           catch (GLib.Error  e)
+           {
+               error (e.message);
+           }
         });
         network.queue_custom (msg);
     }
@@ -168,8 +189,15 @@
 
             var data = msg.response_body.data;
             var stream = new MemoryInputStream.from_data (data);
+           try {
             var pixbuf = new Gdk.Pixbuf.from_stream_at_scale (stream, size, 
size, true);
             image.set_from_pixbuf (pixbuf);
+           }
+           catch (GLib.Error e)
+           {
+           // would be better to know what 'stream' was here
+           error("error with stream: size: %d",size);
+           }
         });
         network.queue_custom (msg);
     }
--- a/src/Notificator.vala
+++ b/src/Notificator.vala
@@ -60,7 +60,8 @@
     }
     
     private bool reconnect () {
-        start ();
+
+        start.begin();
         return false;
     }
     
@@ -82,8 +83,15 @@
         var msg = (string) bytes.get_data ();
         
         var parser = new Json.Parser ();
-        parser.load_from_data (msg, -1);
-        var root = parser.get_root ().get_object ();
+        try {
+        parser.load_from_data (msg, -1);
+        }
+       catch (GLib.Error e)
+       {
+       error("load from data failed message: %s \n msg: %s \n",msg,e.message);
+       }
+       
+         var root = parser.get_root ().get_object ();
         
         var type = root.get_string_member ("event");
         switch (type) {
@@ -115,7 +123,13 @@
         var payload = root.get_string_member ("payload");
         var sanitized = Soup.URI.decode (payload);
         var parser = new Json.Parser ();
-        parser.load_from_data (sanitized, -1);
+       try { 
+           parser.load_from_data (sanitized, -1);
+        }
+       catch (GLib.Error e)
+       {
+       error("load from data failed message: %s \n sanitized: %s 
\n",sanitized,e.message);
+       }
         return parser.get_root ().get_object ();
     }
     
--- a/src/Views/TimelineView.vala
+++ b/src/Views/TimelineView.vala
@@ -172,7 +172,7 @@
             if (can_stream ())
                 on_status_added (status);
         });
-        notificator.start ();
+        notificator.start.begin();
     }
     
     protected virtual bool is_public () {
--- a/src/Watchlist.vala
+++ b/src/Watchlist.vala
@@ -95,7 +95,7 @@
         if (is_hashtag) {
             hashtags.add (entity);
             var notificator = get_notificator (entity);
-            notificator.start ();
+            notificator.start.begin();
             notificators.add (notificator);
             info ("Added #%s", entity);
         }
--- a/src/Widgets/AttachmentWidget.vala
+++ b/src/Widgets/AttachmentWidget.vala
@@ -92,8 +92,19 @@
             var msg = Soup.Form.request_new_from_multipart (url, multipart);
             
             network.queue(msg, (sess, mess) => {
-                var root = network.parse (mess);
+           try {
+                var root = network.parse (mess);
                 attachment = Attachment.parse (root);
+               }
+            catch (GLib.RegexError  e)
+            {
+            error (e.message);
+            }
+            catch (GLib.Error  e)
+            {
+            error (e.message);
+            }
+
                 editable = true;
                 
                 rebind ();
@@ -102,8 +113,9 @@
         }
         catch (Error e) {
             error (e.message);
-            app.error (_("File read error"), _("Can't read file %s: 
%s").printf (uri, e.message));
-        }
+// this line is never reached apparently error throws or something.
+//            app.error (_("File read error"), _("Can't read file %s: 
%s").printf (uri, e.message));
+        }
     }
     
     private bool on_clicked (EventButton ev){
--- a/src/Widgets/ImageToggleButton.vala
+++ b/src/Widgets/ImageToggleButton.vala
@@ -11,12 +11,13 @@
         icon = new Gtk.Image.from_icon_name (icon_name, icon_size);
         add (icon);
         show_all ();
+       this.focus_on_click = false;
     }
     
     public void set_action () {
         can_default = false;
-        set_focus_on_click (false);
-        get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
+       //set_focus_on_click(this,false);
+        get_style_context().add_class (Gtk.STYLE_CLASS_FLAT);
     }
     
 }

Reply via email to