EasyPro challengePython

Fail Fast — Don't Ignore Errors

PythonClean CodeError HandlingFail Fast

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 wrong

Refactor `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

Test #1Valid JSON is parsed
Input: ["{\"a\":1}"]
Output: {"ok":true,"value":{"a":1}}
Test #2Valid array JSON
Input: ["[1,2,3]"]
Output: {"ok":true,"value":[1,2,3]}
Test #3Invalid JSON reports failure explicitly
Input: ["invalid"]
Output: {"ok":false,"error":"Invalid JSON"}