InterviewStack.io LogoInterviewStack.io

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.

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.

MediumTechnical
28 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?

MediumTechnical
24 practiced

While testing, you trigger a server error and see a full stack trace in the API response, including internal file paths. Is this worth filing as a bug, and how would you write it up so it gets fixed with the right urgency?

EasyTechnical
35 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?

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.

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.