Code Quality, Error Handling, and Defensive Programming Questions

Writing robust, high-quality code that fails safely. Covers defensive programming, input validation, error handling and fault tolerance, logging for diagnosability, and general engineering-quality standards. Includes anticipating failure modes and making code resilient to bad inputs and unexpected states.

HardTechnical
30 practiced

For a public API, design a policy that decides what error detail is safe to return to CLIENTS versus what stays only in internal logs. Include examples of safe client-facing error formats, how to include a correlation id without leaking internals, and whether/when to include a stack trace in a log versus an API response. Propose an automated test that ensures no sensitive field ever leaks into a client-facing response.

MediumTechnical
29 practiced

What is fuzz testing, and how would you use it to find defensive-programming gaps, like unhandled exceptions or crashes, in a service that parses untrusted file uploads?

EasyTechnical
36 practiced

A debug log statement accidentally includes a raw API key or password in plaintext, and it ships to production before anyone catches it in review. How do you prevent this class of bug systematically, not just rely on catching it in the next code review?

EasyTechnical
23 practiced

Write a small JavaScript function safeParseJSON(jsonString) that returns an object {success: boolean, value: any, error: string|null}. It must not throw, must handle invalid JSON gracefully, and must not allow prototype pollution (it must avoid assigning to proto or constructor). Also write one example unit test in Jest for an invalid input.

HardTechnical
29 practiced

How do you decide which inputs in a system need strict validation versus which can be trusted, in a system with multiple internal services calling each other as well as external clients?

Unlock Full Question Bank

Get access to all 10 Code Quality, Error Handling, and Defensive Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.