InterviewStack.io LogoInterviewStack.io

Error Handling and Code Quality Questions

Focuses on writing production quality code and scripts that are defensive, maintainable, and fail gracefully. Covers anticipating and handling failures such as exceptions, missing files, network errors, and process exit codes; using language specific constructs for error control for example try except blocks in Python or set minus e patterns in shell scripts; validating inputs; producing clear error messages and logs; and avoiding common pitfalls that lead to silent failures. Also includes code quality best practices such as readable naming and code structure, using standard libraries instead of reinventing functionality, writing testable code and unit tests, and designing for maintainability and observability.

EasyTechnical
0 practiced
Write pytest unit tests for a Python function read_file_lines(path) that should raise FileNotFoundError if the file is missing and return a list of stripped lines if present. Tests should use tmp_path to create files and monkeypatch or pytest-mock to simulate a PermissionError when opening the file. Provide the tests only, and explain assertions and fixtures used.
MediumTechnical
0 practiced
Design and implement a simple in-process circuit breaker in Python with states closed, open, and half-open. The breaker should open after a configurable failure threshold within a sliding window, stay open for a reset_timeout, and transition to half-open where limited requests are allowed. Provide the class API, a basic thread-safe implementation, and describe race conditions and how you would test it under concurrent load.
MediumTechnical
0 practiced
Implement a Python decorator retry_on_exception that retries a synchronous function up to N times with exponential backoff and optional full jitter. Signature: retry_on_exception(retries=3, base_delay=0.5, max_delay=10, exceptions=(Exception,), jitter=True). Requirements: sleep between retries, re-raise the last exception if all retries fail, and preserve the wrapped function's metadata. Discuss limitations in multi-threaded environments.
MediumTechnical
0 practiced
Refactor the following Python function into testable components. Original function reads a config file, makes an HTTP call to an external service, parses the JSON response, and writes results to disk. Describe how to separate I/O from logic, apply dependency injection, and present a refactored sketch with clear interfaces so each part can be unit tested with mocks.
HardTechnical
0 practiced
Explain secure error handling policies an SRE should enforce: which types of sensitive data must be redacted from logs and error messages, how to implement redaction and blacklisting, and patterns to prevent error-based information disclosure in public APIs. Give examples of unsafe and safe error messages.

Unlock Full Question Bank

Get access to hundreds of Error Handling and Code Quality interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.