Rfaulk has submitted this change and it was merged.

Change subject: fix. logic to account for empty targets.
......................................................................


fix. logic to account for empty targets.

Change-Id: I253159f111bcb4c54cb6cf9ccc3940e1a4089dc8
---
M user_metrics/api/broker.py
1 file changed, 13 insertions(+), 11 deletions(-)

Approvals:
  Rfaulk: Verified; Looks good to me, approved



diff --git a/user_metrics/api/broker.py b/user_metrics/api/broker.py
index 3bce31f..eb30d39 100644
--- a/user_metrics/api/broker.py
+++ b/user_metrics/api/broker.py
@@ -142,17 +142,19 @@
         """
         try:
             with open(target, 'r') as f:
-                lines = f.read().split('\n')
-                if not len(lines):
-                    try:
-                        item = json.loads(lines[0])
-                        key = item.keys()[0]
-                    except (KeyError, ValueError):
-                        logging.error(__name__ + ' :: FileBroker.pop - '
-                                                 'Could not parse key.')
-                        return None
-                    self.remove(target, key)
-                    return item[key]
+                contents = f.read()
+                if contents:
+                    lines = contents.split('\n')
+                    if len(lines):
+                        try:
+                            item = json.loads(lines[0])
+                            key = item.keys()[0]
+                        except (KeyError, ValueError):
+                            logging.error(__name__ + ' :: FileBroker.pop - '
+                                                     'Could not parse key.')
+                            return None
+                        self.remove(target, key)
+                        return item[key]
         except IOError:
             with open(target, 'w'):
                 pass

-- 
To view, visit https://gerrit.wikimedia.org/r/73777
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I253159f111bcb4c54cb6cf9ccc3940e1a4089dc8
Gerrit-PatchSet: 1
Gerrit-Project: analytics/user-metrics
Gerrit-Branch: repair_runtime
Gerrit-Owner: Rfaulk <[email protected]>
Gerrit-Reviewer: Rfaulk <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to