Level 3 / Project 06 - Structured Error Handler¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| — | This project | — | — | Flashcards | — | Browser |
Estimated time: 40 minutes
Focus¶
- typed errors and safe propagation
Why this project exists¶
This project gives you level-appropriate practice in a realistic operations context. Goal: run the baseline, alter behavior, break one assumption, recover safely, and explain the fix.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-3/06-structured-error-handler
python project.py records.json --schema schema.json
python project.py records.json --schema schema.json --json
pytest -q
Expected terminal output¶
Expected artifacts¶
- Validation results on stdout
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a
rangerule that validates numeric values (e.g., age 0-150). - Add an
--exit-codeflag that returns non-zero if any record fails. - Add error severity levels to the schema (warning vs error).
Break it (required) — Core¶
- Pass a schema file that doesn't exist — what error appears?
- Pass records with a field not in the schema — is it validated or ignored?
- Trigger an unexpected exception inside a validator — does
safe_processcatch it?
Fix it (required) — Core¶
- Add a friendly error message when schema or records file is missing.
- Validate the schema itself before processing (are rule names valid?).
- Ensure
capture_errorworks for all built-in exception types.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why create a custom exception hierarchy (AppError, ValidationError, etc.)?
- What is the "Result pattern" and how does
OperationResultimplement it? - How does
safe_processdiffer from scattering try/except everywhere? - What does
traceback.format_exceptionreturn and when would you use it?
Mastery check¶
You can move on when you can: - design a custom exception hierarchy, - use the Result pattern instead of exceptions for flow control, - accumulate errors across a batch without crashing, - write structured error reports with codes and context.
Related Concepts¶
Stuck? Ask AI¶
If you are stuck after trying for 20 minutes, use one of these prompts:
- "I am working on Structured Error Handler. I got this error: [paste error]. Can you explain what this error means without giving me the fix?"
- "I am trying to create custom exception classes. Can you show me how to define a custom exception with extra attributes, using a different domain than mine?"
- "Can you explain when to raise an exception vs when to return an error value?"
| ← Prev | Home | Next → |
|---|---|---|