Interview Prep/Python for DevOps/Runtime, file, subprocess & encoding errors

`NameError: name 'log' is not defined` only when an error path runs in production.

BeginnerTroubleshootingRuntime, file, subprocess & encoding errors
Answer

Likely causes → A typo or missing import in a rarely executed branch (often an except block), which Python only detects when that line runs.

Diagnose → Run ruff check (F821 Undefined name) and mypy; both find this statically.

Fix → Define/import the name; add a test that exercises the error path.

Prevent → Linting in CI catches this class of bug in seconds; test failure paths, not just the happy path.

All Python for DevOps questions Roadmap: Python for automation

More on Runtime, file, subprocess & encoding errors