whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [1/1] Commit 3c9a654: treat log as utf-8, recover from individual errors
Date Fri, 29 Jan 2016 12:04:57 GMT
Commit 3c9a6546a7c606cf815b758055dc6563a1c9d02a:
    treat log as utf-8, recover from individual errors


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
www/status/monitors/public_json.rb                           | ++++++++ -----
------------------------------------------------------------
52 changes: 32 additions, 20 deletions.
------------------------------------------------------------


diff --git a/www/status/monitors/public_json.rb b/www/status/monitors/public_json.rb
index 0102f23..a9858e1 100644
--- a/www/status/monitors/public_json.rb
+++ b/www/status/monitors/public_json.rb
@@ -8,27 +8,39 @@ def Monitor.public_json(previous_status)
   status = {}
 
   Dir[logs].each do |log|
-    name = File.basename(log).sub('public-', '')
-
-    status[name] = {
-      href: "../logs/#{File.basename(log)}",
-      mtime: File.mtime(log)
-    }
-
-    contents = File.read(log)
-
-    # Ignore Wunderbar logging for normal messages (TODO ignore _WARN ?)
-    contents.sub! /^(_INFO|_DEBUG) .*\n+/, ''
-
-    # diff -u output:
-    if contents.sub! /^--- .*?\n(\n|\Z)/m, ''
-      status[name].merge! level: 'info', title: 'updated'
+    begin
+      name = File.basename(log).sub('public-', '')
+
+      status[name] = {
+        href: "../logs/#{File.basename(log)}",
+        mtime: File.mtime(log)
+      }
+
+      contents = File.read(log, encoding: Encoding::UTF_8)
+
+      # Ignore Wunderbar logging for normal messages (TODO ignore _WARN ?)
+      contents.sub! /^(_INFO|_DEBUG) .*\n+/, ''
+
+      # diff -u output:
+      if contents.sub! /^--- .*?\n(\n|\Z)/m, ''
+        status[name].merge! level: 'info', title: 'updated'
+      end
+
+      unless contents.empty?
+        status[name].merge! level: 'danger', data: contents.split("\n")
+      end
+    rescue Exception => e
+      status[name] = {
+        level: 'danger',
+        data: {
+          exception: {
+            level: 'danger',
+            text: e.inspect,
+            data: e.backtrace
+          }
+        }
+      }
     end
-
-    unless contents.empty?
-      status[name].merge! level: 'danger', data: contents.split("\n")
-    end
-
   end
 
   {data: status}

Mime
View raw message