PeaBox Lab › PeaLang › Learn › Chapter 6 › Lesson 5

Part II — Intermediate Development · Chapter 6 · Lesson 5 of 5 · 8 min read

Chapter 6 Checkpoint: Fault-Tolerant Import Processor

Checkpoint level: Intermediate

Purpose: Integrate diagnostic classification, boundary validation, assertions, structured exception handling, recovery accounting, cleanup, debugging, and safe evidence in one resilient import workflow.

Checkpoint outcomes

By completing this checkpoint, you will demonstrate that you can:

Project scenario

A business application imports source-defined transaction records. Each record must be validated, normalized, enriched through a simulated provider, and converted into an accepted result or a safe failure result. Ordinary invalid records and per-record provider failures do not stop later records. A designated fatal provider condition aborts the batch after required cleanup.

The checkpoint uses no live network, file, database, credential, or process access. Provider behavior is simulated deterministically so every path is reproducible.

6C.1 Input record contract

FieldMeaningValidation
record_idStable import identifierRequired nonempty string
account_codeTarget business accountRequired nonempty string
amountTransaction amountRequired number greater than zero
currencyCurrency codeOne of USD, EUR, or INR
categoryBusiness classificationOne of standard, priority, or review
provider_modeDeterministic provider behaviorok, transient_error, permanent_error, or fatal_error
tagsOptional metadata labelsRequired list of at most ten nonempty strings

6C.2 Validation policy

6C.3 Simulated provider policy

ModeBehaviorRecovery
okReturns a deterministic enrichment mapAccept the record
transient_errorThrows on the first call and succeeds on the secondRetry once within a bounded policy
permanent_errorThrows on every callCatch per record and continue
fatal_errorThrows a batch-invalidating failurePerform cleanup and abort the batch

6C.4 Retry contract

Only transient_error may be retried. The retry policy is:

6C.5 Record outcomes

Every inspected record before a fatal batch stop must produce exactly one outcome:

Records after a fatal stop are not_inspected and must not receive fabricated outcomes.

6C.6 Required result shape

Return a portable summary map containing:

6C.7 Per-record result contract

Each inspected record result must contain:

6C.8 Required invariants

6C.9 Processing pipeline

6C.10 Exception-handling constraints

6C.11 Assertion plan

Use assertions only for internal guarantees, including:

6C.12 Diagnostic classification

ConditionClassificationResponse
Missing field or invalid amountExpected validation failureStructured invalid result
Transient provider failureRetryable provider exceptionRetry once
Permanent provider failurePer-record HostErrorProvider-failed result; continue
Fatal provider failureBatch HostErrorCleanup and abort
Broken accounting assertionInternal defectStop; do not continue with uncertain state
Instruction limit exceededResourceLimitErrorTerminate under host policy

6C.13 Safe evidence

Record only information needed for testing and operations:

Do not record credentials, full sensitive payloads, arbitrary host representations, or unrestricted stack data in public output.

6C.14 Required test matrix

CaseInputExpected emphasis
AEmpty listComplete, all counts zero
BOne valid ok recordAccepted in one attempt
COne ordinary invalid recordInvalid, zero provider attempts
DTransient provider recordAccepted on second attempt
EPermanent provider errorProvider failed; later record continues
FFatal error firstAbort; all later records not inspected
GFatal error in middleEarlier results retained; later inputs untouched
HFatal error lastAll records inspected; batch failed
IMixed valid, invalid, transient, and permanentAll accounting and ordering
JExact amount and size boundariesInclusive and exclusive rules

6C.15 Deliberate defect matrix

Introduce and diagnose these temporary defects:

6C.16 Debugging requirement

For at least four defects:

At least one investigation must cover catch/finally behavior and one must cover accounting after a fatal stop.

6C.17 Interpreter and VM parity

Run deterministic valid, invalid, transient, permanent, and fatal cases through both engines where supported. Compare:

Reduce and report any divergence rather than accepting one engine as automatically correct.

6C.18 Resource and security tests

6C.19 Acceptance criteria

6C.20 Submission package

6C.21 Assessment rubric

AreaEvidence of mastery
ValidationMalformed input is classified safely before provider work.
Exception handlingTry, catch, throw, and finally express the documented policy.
RecoveryRetries, continuation, and fatal propagation are correct.
ConsistencyPartial state and all accounting invariants are controlled.
DiagnosticsMessages, codes, locations, and redaction are useful and safe.
DebuggingRoot causes are found through focused evidence and regression tests.
ParityInterpreter and VM behavior agrees or differences are reduced.
SecurityCapabilities, resources, output, and sensitive data remain bounded.

Completion standard: Every required test passes, fatal and recoverable paths follow policy, every invariant holds, source data remains unchanged, and the learner can explain each provider attempt, result, cleanup action, and batch exit.

6C.22 Reflection questions

Chapter 6 summary

You can now classify failures, write actionable diagnostics, validate boundaries, state assertions and invariants, recover with structured exception handling, clean up reliably, and debug with source and protocol tools. The fault-tolerant import processor combines these practices into a bounded workflow with explicit record outcomes, fatal-stop semantics, portable results, and verifiable accounting.

Transition to Chapter 7

Chapter 7 introduces optional typing and semantic analysis. The next lesson covers variable, parameter, and return annotations and explains how stronger contracts complement—rather than replace—runtime validation.

Checkpoint status: Ready for review.

← Previous Next →