Silently swallowing errors hides bugs and makes debugging a nightmare.
# dirty — errors are swallowed
def solve(json_str):
try:
import json
return json.loads(json_str)
except Exception:
return None # swallowed — caller has no idea what went wrongRefactor `solve(json_str)` so failure is never silent: on success return {'ok': True, 'value': <parsed>}, on failure return {'ok': False, 'error': 'Invalid JSON'} — never a bare None that hides which case happened.
Sample tests