From f308216bbcee55b860bd8087b54cc0591c7ef5e0 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 10 Mar 2018 19:09:48 +0000 Subject: [PATCH] Always collect exceptions instead of swallowing them --- SparkleShare/Common/AboutController.cs | 3 ++- SparkleShare/Common/SetupController.cs | 4 ++-- SparkleShare/Linux/UserInterfaceHelpers.cs | 5 ++++- Sparkles/Git/GitRepository.cs | 17 +++++++++-------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/SparkleShare/Common/AboutController.cs b/SparkleShare/Common/AboutController.cs index 9f7436e4..134b1e62 100644 --- a/SparkleShare/Common/AboutController.cs +++ b/SparkleShare/Common/AboutController.cs @@ -73,7 +73,8 @@ namespace SparkleShare { else UpdateLabelEvent ("✓ You are running the latest version"); - } catch { + } catch (Exception e) { + Logger.LogInfo ("UI", "Failed to download " + uri , e); UpdateLabelEvent ("Couldn’t check for updates\t"); } } diff --git a/SparkleShare/Common/SetupController.cs b/SparkleShare/Common/SetupController.cs index 19b950ea..3e34173a 100644 --- a/SparkleShare/Common/SetupController.cs +++ b/SparkleShare/Common/SetupController.cs @@ -346,8 +346,8 @@ namespace SparkleShare { Logger.LogInfo ("Controller", "Added preset for " + uri.Host); } - } catch { - Logger.LogInfo ("Controller", "Failed adding preset for " + uri.Host); + } catch (Exception e) { + Logger.LogInfo ("Controller", "Failed adding preset for " + uri.Host, e); } } diff --git a/SparkleShare/Linux/UserInterfaceHelpers.cs b/SparkleShare/Linux/UserInterfaceHelpers.cs index 648bfbd4..34d760df 100755 --- a/SparkleShare/Linux/UserInterfaceHelpers.cs +++ b/SparkleShare/Linux/UserInterfaceHelpers.cs @@ -19,6 +19,7 @@ using System; using System.IO; using Gtk; +using Sparkles; namespace SparkleShare { @@ -35,7 +36,9 @@ namespace SparkleShare { try { return icon_theme.LoadIcon (name, size, IconLookupFlags.GenericFallback); - } catch { + } catch (Exception e) { + Logger.LogInfo ("UI", "Failed to load icon " + name + " of size " + size, e); + try { return icon_theme.LoadIcon ("gtk-missing-image", size, IconLookupFlags.GenericFallback); diff --git a/Sparkles/Git/GitRepository.cs b/Sparkles/Git/GitRepository.cs index 560a93e3..91f90f71 100644 --- a/Sparkles/Git/GitRepository.cs +++ b/Sparkles/Git/GitRepository.cs @@ -102,7 +102,8 @@ namespace Sparkles.Git { string size = File.ReadAllText (file_path); return double.Parse (size); - } catch { + } catch (Exception e) { + Logger.LogInfo ("Git", Name + " | Failed to parse " + file_path, e); return 0; } } @@ -117,7 +118,8 @@ namespace Sparkles.Git { string size = File.ReadAllText (file_path); return double.Parse (size); - } catch { + } catch (Exception e) { + Logger.LogInfo ("Git", Name + " | Failed to parse " + file_path, e); return 0; } } @@ -638,16 +640,15 @@ namespace Sparkles.Git { try { File.Move (local_file_path, target_file_path); - } catch { - Logger.LogInfo ("Git", - Name + " | Could not move \"" + local_file_path + "\" to \"" + target_file_path + "\""); + } catch (Exception e) { + string message = string.Format ("Failed to move \"{0}\" to \"{1}\"", local_file_path, target_file_path); + Logger.LogInfo ("Git", Name + " | " + message, e); } // ...and restore the most recent revision git = new GitCommand (LocalPath, "checkout " + CurrentRevision + " \"" + path + "\""); git.StartAndWaitForExit (); - if (target_file_path.StartsWith (LocalPath)) new Thread (() => OnFileActivity (null)).Start (); } @@ -966,8 +967,8 @@ namespace Sparkles.Git { File.WriteAllText (Path.Combine (path, ".empty"), "I'm a folder!"); File.SetAttributes (Path.Combine (path, ".empty"), FileAttributes.Hidden); - } catch { - Logger.LogInfo ("Git", Name + " | Failed adding empty folder " + path); + } catch (Exception e) { + Logger.LogInfo ("Git", Name + " | Failed adding empty folder " + path, e); } } }