disallow bare except statements (#6017)

This commit is contained in:
Maximilian Hils 2023-03-26 15:57:48 +02:00 committed by GitHub
parent 7bf388979a
commit 555a2d2199
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 16 additions and 16 deletions

View File

@ -149,7 +149,7 @@ class MappingAddon:
try:
for css_sel, soup in value.items():
store[css_sel] = str(soup)
except:
except Exception:
raise RuntimeError(value)
return store

View File

@ -561,7 +561,7 @@ class ProtoParser:
return intended_decoding, self.decode_as(
intended_decoding, try_as_packed
)
except:
except Exception:
if int(self.wire_value).bit_length() > 32:
# ignore the fact that varint could exceed 64bit (would violate the specs)
return ProtoParser.DecodedTypes.uint64, self.wire_value
@ -572,21 +572,21 @@ class ProtoParser:
return intended_decoding, self.decode_as(
intended_decoding, try_as_packed
)
except:
except Exception:
return ProtoParser.DecodedTypes.fixed64, self.wire_value
elif self.wire_type == ProtoParser.WireTypes.bit_32:
try:
return intended_decoding, self.decode_as(
intended_decoding, try_as_packed
)
except:
except Exception:
return ProtoParser.DecodedTypes.fixed32, self.wire_value
elif self.wire_type == ProtoParser.WireTypes.len_delimited:
try:
return intended_decoding, self.decode_as(
intended_decoding, try_as_packed
)
except:
except Exception:
# failover strategy: message --> string (valid UTF-8) --> bytes
len_delimited_strategy: list[ProtoParser.DecodedTypes] = [
ProtoParser.DecodedTypes.message,
@ -601,7 +601,7 @@ class ProtoParser:
return failover_decoding, self.decode_as(
failover_decoding, False
)
except:
except Exception:
pass
# we should never get here (could not be added to tests)
@ -1074,7 +1074,7 @@ class ViewGrpcProtobuf(base.View):
if h in self.__valid_grpc_encodings
else self.__valid_grpc_encodings[0]
)
except:
except Exception:
grpc_encoding = self.__valid_grpc_encodings[0]
text_iter = format_grpc(

View File

@ -39,7 +39,7 @@ def format_pbuf(raw):
try:
pairs = _parse_proto(raw)
except:
except Exception:
return False
stack.extend([(pair, 0) for pair in pairs[::-1]])
@ -62,7 +62,7 @@ def format_pbuf(raw):
pairs = _parse_proto(body) # type: ignore
stack.extend([(pair, indent_level + 2) for pair in pairs[::-1]])
write_buf(out, pair.field_tag, None, indent_level)
except:
except Exception:
write_buf(out, pair.field_tag, body, indent_level)
if stack:

View File

@ -12,7 +12,7 @@ class ViewWBXML(base.View):
parsedContent = parser.xmlString
if parsedContent:
return "WBXML", base.format_text(parsedContent)
except:
except Exception:
return None
def render_priority(

View File

@ -64,7 +64,7 @@ class ResourceRecord(serializable.SerializableDataclass):
return self.domain_name
if self.type == types.TXT:
return self.text
except:
except Exception:
return f"0x{self.data.hex()} (invalid {types.to_str(self.type)} data)"
return f"0x{self.data.hex()}"

View File

@ -132,7 +132,7 @@ class ConsoleMaster(master.Master):
with self.uistopped():
try:
subprocess.call(cmd)
except:
except Exception:
signals.status_message.send(message="Can't start editor: %s" % c)
else:
with open(name, "r" if text else "rb") as f:
@ -167,7 +167,7 @@ class ConsoleMaster(master.Master):
with self.uistopped():
try:
subprocess.call(cmd, shell=False)
except:
except Exception:
signals.status_message.send(
message="Can't start external viewer: %s" % " ".join(c)
)

View File

@ -39,7 +39,7 @@ def dump_info(signal=None, frame=None, file=sys.stdout): # pragma: no cover
try:
import psutil
except:
except ModuleNotFoundError:
print("(psutil not installed, skipping some debug info)")
else:
p = psutil.Process()

View File

@ -1,7 +1,7 @@
[flake8]
max-line-length = 140
max-complexity = 25
ignore = E203,E251,E252,C901,W292,W503,W504,W605,E722,E741,E126,F541
ignore = E203,E251,E252,C901,W292,W503,W504,W605,E741,E126,F541
exclude = mitmproxy/contrib/*,test/mitmproxy/data/*,release/build/*
addons = file,open,basestring,xrange,unicode,long,cmp

View File

@ -99,7 +99,7 @@ def pytest_runtestloop(session):
(s, cov.report(s, ignore_errors=True, file=null)) for s in files
]
coverage_values[name] = (overall, singles)
except:
except Exception:
pass
if any(v < 100 for v, _ in coverage_values.values()):