From 5e62118e14dda4999ac62eb1d802b568c4c23189 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 31 Dec 2017 00:23:43 +0100 Subject: [PATCH] hush somewhat-real problems found by static analysis These would have caused problems if a certain unlikely code path was taken: mostly error-handling pathways. --- misc/coding_tools/check-miscaptures.py | 2 +- src/allmydata/frontends/magic_folder.py | 2 +- src/allmydata/scripts/common_http.py | 2 +- src/allmydata/util/log.py | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/misc/coding_tools/check-miscaptures.py b/misc/coding_tools/check-miscaptures.py index 07b94a5bd..5a21190f7 100644 --- a/misc/coding_tools/check-miscaptures.py +++ b/misc/coding_tools/check-miscaptures.py @@ -62,7 +62,7 @@ def check_loop(ast, results): # contains another 'for' loop. childnodes = funcnode.getChildNodes()[len(funcnode.defaults):] for child in childnodes: - check_ast(funcnode, results) + check_ast(child, results) def collect_assigned_and_nested(ast, assigned, nested): """ diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index 34de0ed18..7e1af3511 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -243,7 +243,7 @@ class MagicFolder(service.MultiService): clock = clock or reactor db = magicfolderdb.get_magicfolderdb(dbfile, create_version=(magicfolderdb.SCHEMA_v1, 1)) if db is None: - return Failure(Exception('ERROR: Unable to load magic folder db.')) + raise Exception('ERROR: Unable to load magic folder db.') # for tests self._client = client diff --git a/src/allmydata/scripts/common_http.py b/src/allmydata/scripts/common_http.py index 1964672bd..19b7b0b56 100644 --- a/src/allmydata/scripts/common_http.py +++ b/src/allmydata/scripts/common_http.py @@ -32,7 +32,7 @@ class BadResponse(object): self.status = -1 self.reason = "Error trying to connect to %s: %s" % (url, err) self.error = err - def read(self): + def read(self, length=0): return "" diff --git a/src/allmydata/util/log.py b/src/allmydata/util/log.py index 199318c3c..454002000 100644 --- a/src/allmydata/util/log.py +++ b/src/allmydata/util/log.py @@ -36,10 +36,11 @@ class LogMixin(object): def log(self, msg, facility=None, parent=None, *args, **kwargs): if facility is None: facility = self._facility + pmsgid = None if parent is None: pmsgid = self._parentmsgid - if pmsgid is None: - pmsgid = self._grandparentmsgid + if pmsgid is None: + pmsgid = self._grandparentmsgid msgid = log.msg(msg, facility=facility, parent=pmsgid, *args, **kwargs) if self._parentmsgid is None: self._parentmsgid = msgid