Quiz: Errors, Logs and Knowing What Happened¶
Test your understanding of exceptions, bare catch blocks, logging, request IDs, error tracking, monitoring, alerts and heartbeat checks with these review questions.
1. What is a bare catch block?¶
- A catch block that handles one named failure and lets the rest keep going
- A catch block that writes the error to the logs and rethrows it
- A catch block that catches every exception and does nothing useful with it
- A try block with no catch at all
Show Answer
The correct answer is C. A bare catch block swallows every failure, often with an empty body or a comment. It keeps the app from crashing, which is why agents write it when asked to make an error go away, but the failure vanishes from the member, the logs and the error tracker. The dating-safety app had about 24 of them. Option A describes good error handling with named failures.
Concept Tested: Bare Catch Block
See: Bare Catch Blocks
2. What is a request ID?¶
- The ID of the member who sent the request
- A unique label the server gives each incoming request and attaches to every log entry written while handling it
- The number an uptime check sends to the health endpoint
- The order in which requests reached the server today
Show Answer
The correct answer is B. A request ID, also called a correlation ID, lets you filter a busy log stream down to one request and read its trip from route to adapter to database. That is request path tracing. A member ID (A) groups many requests together. The dating-safety app had no request IDs, which was fine with one scan running and not fine with fifty at once.
Concept Tested: Request ID
3. Why shouldn't a member see a stack trace when a photo upload fails?¶
- It shows file names, line numbers and internal details that help attackers and mean nothing to the member
- Stack traces are too long for a phone screen
- Browsers can't display stack traces
- Stack traces are only created in development
Show Answer
The correct answer is A. Stack trace exposure hands an attacker a map of the app's insides and leaves the member with no idea what to do. A plain message says what happened and what to try next, such as "Your photo didn't upload. Please try again in a few minutes." The trace still matters, so send it to the logs and the error tracker. Length (B) is a minor point, and traces happen in production too (D).
Concept Tested: Stack Trace Exposure
4. Why does an error tracking service miss failures swallowed by a bare catch block?¶
- Error trackers only watch the front end
- Error trackers only report each failure once a day
- Error trackers ignore failures from outside vendors
- An error tracker only sees exceptions that reach it, and a bare catch block stops them first
Show Answer
The correct answer is D. A tool such as Sentry collects unhandled exceptions, groups repeats and tells you when a new one appears. If a catch block swallows the exception, it never travels far enough to be reported. That's why fixing bare catch blocks and adding error tracking go together. Error trackers cover the server as well as the front end (A), and they report as failures happen (B).
Concept Tested: Error Tracking Service
5. The author's scheduled job was being called with GET instead of POST, so its code never ran. Why would the app's logs, or an error tracker, show nothing?¶
- The logs were turned off at night
- The error tracker's free tier was used up
- Both report on code that ran, and the job's code was never reached
- The scheduler deleted the log lines after each call
Show Answer
The correct answer is C. A job that never ran makes no noise. No exception was thrown, because the job's code never started, so there was nothing for the logs or an error tracker to record. Only the platform's raw HTTP logs showed each scheduled call arriving with the wrong method. The fix was one line, but finding it took hours. A heartbeat check would have turned the silence into an alert.
Concept Tested: Job That Never Ran
6. Your nightly purge job could fail by throwing, or by never being called at all. What should you add so both are caught?¶
- A log line at the start of the job
- A heartbeat check that expects a ping at the end of each successful run and alerts when none arrives
- An uptime check on the home page
- A try-catch block around the whole job that logs "purge done"
Show Answer
The correct answer is B. A heartbeat check asks "did the thing I expected happen?" If the purge throws, the ping at the end never goes. If the scheduler never calls the job, the ping never goes either. Both alert. A log line at the start (A) proves only that the job began, and it can't appear if the job never runs. An uptime check (C) watches the server, not the job. Option D would report success after a failure.
Concept Tested: Heartbeat Check
See: Heartbeat Checks
7. An agent writes a /health route that calls the image-search vendor to prove everything works. What should you tell it?¶
- "Good, call every vendor so we know they're all up."
- "Have it return 200 always, so the uptime check never fails."
- "Remove the database query too, so the check is faster."
- "Run
select 1against the database and don't call paid vendors, since the uptime check hits it every few minutes."
Show Answer
The correct answer is D. A health check should report whether the app itself works, using the smallest possible database query. An uptime service calls it every one to five minutes, so a paid vendor call there runs up a bill and marks the whole app down whenever one vendor has a bad hour. Vendor health belongs in its own signal. Returning 200 always (B) makes the check lie. Dropping the database query (C) misses a down database.
Concept Tested: Health Check Endpoint
8. The server logs every incoming request in full to help with debugging. What should you check first?¶
- Whether headers such as the session cookie or an API key are being written to the logs
- Whether the log lines are too long to read
- Whether the logs use the info level
- Whether the logs are sorted by time
Show Answer
The correct answer is A. Logging a whole request often writes the member's session token or an API key into the logs, which are kept for days and read by more people and tools than your environment variables. That's secrets in logs, a leak path from Chapter 6. Use a logging library with redaction for headers and fields like authorization, cookie and password. Length (B), level (C) and order (D) don't expose anything.
Concept Tested: Secrets in Logs
See: Secrets in Logs
9. The no-false-all-clear rule keeps a down vendor from looking like a clean result to members. Why should you still watch the share of checks marked "not checked" for each vendor?¶
- Members complain more when they see "not checked"
- The rule protects members, but if a vendor stays down, every scan quietly gets less useful and nobody tells you
- A high share of "not checked" lowers the vendor's price
- The rule stops working when the share passes 50 percent
Show Answer
The correct answer is B. The rule makes a vendor outage truthful on the results page. It doesn't make anyone fix it. If the image-search key expired, every scan would say "not checked" for that check for weeks. A rise from the usual share is the signal that a vendor, a key or an adapter needs attention. The rule doesn't stop working at any share (D), and vendor pricing doesn't depend on it (C).
Concept Tested: Monitoring
See: A Worked Example: What to Watch for the Dating-Safety App
10. A builder gets forty alerts a day, mostly for brief slowdowns that fix themselves, and has started muting the channel. What is the main risk, and the fix?¶
- The alerts cost money, so turn them all off
- The builder will miss nothing, since important alerts are louder
- Alert fatigue: a real outage will be ignored like the rest, so alert only on what needs action and require it to last a set time
- The alerts are too short, so add more detail to each one
Show Answer
The correct answer is C. Alert fatigue is the pharmacist clicking past drug warnings without reading them. Once people ignore alerts, the one that matters gets ignored too. Each alert needs a signal, a line, how long it must stay over the line, and who gets told. "Two failed uptime checks in a row" filters out blips. Turning everything off (A) removes the warning. Alerts don't sort themselves by loudness (B). More detail (D) doesn't reduce the noise.
Concept Tested: Alert Fatigue