31. Build errors (pocket version)

TL;DR (5 lines)

  • Diagnostics point back to a broken contract.
  • A valid and invalid pair is the right teaching unit.
  • Smaller repros are more educational than giant failing files.
  • The first useful diagnostic move is naming the broken contract.
  • Actionable fixes start from structure, not from guesswork.

Concrete Problem

Readers often see diagnostics as messages to memorize rather than structured signals tied to a failing contract.

Coherent example

space demo/diagnostics

proc safe_div(total: int, count: int) -> int {
  if count == 0 { give 0 }
  give total
}

export *

Complete examples

Each block below is a complete reading unit with its own boundary, data shape, and observable result.

Primary coherent example

This is the compact chapter anchor used by the surrounding explanation.

space demo/diagnostics

proc safe_div(total: int, count: int) -> int {
  if count == 0 { give 0 }
  give total
}

export *

Reduced failing boundary

This example keeps the operation small so a diagnostic maps to one contract.

space examples/diagnostics/reduced

proc require_positive(value: int) -> int {
  if value <= 0 { give 11 }
  give value
}

proc main(args: list[string]) -> int {
  give require_positive(3)
}

export *

Corrected diagnostic path

This variant names the correction instead of leaving the failure implicit.

space examples/diagnostics/correction

proc safe_index(index: int, size: int) -> int {
  if size <= 0 { give 40 }
  if index < 0 { give 41 }
  if index >= size { give 42 }
  give index
}

proc main(args: list[string]) -> int {
  give safe_index(1, 3)
}

export *

Immediate work for this chapter

  • Connect each diagnostic to the exact contract it protects.
  • Keep repro code minimal and complete.
  • Show the corrected shape immediately after the broken shape.
  • Keep the first code block complete and aligned with current Vitte docs syntax.
  • Keep the invalid block focused on one broken contract only.
  • Replace generic prose with one concrete rule visible in the code.
  • Keep every example small enough to review from top to bottom.

Chapter override: 31-build-errors.html

Dedicated problem

31. Build errors needs a concrete production-grade anchor around expected shape, actual shape, and correction path. The page should keep the examples, diagnostics, and review rules tied to that exact boundary instead of drifting back to generic tutorial prose.

Specific complete examples

31. Build errors chapter anchor

The primary example is promoted here as the first chapter-specific production reading unit.

space demo/diagnostics

proc safe_div(total: int, count: int) -> int {
  if count == 0 { give 0 }
  give total
}

export *

Reduced failing boundary

This example keeps the operation small so a diagnostic maps to one contract.

space examples/diagnostics/reduced

proc require_positive(value: int) -> int {
  if value <= 0 { give 11 }
  give value
}

proc main(args: list[string]) -> int {
  give require_positive(3)
}

export *

Corrected diagnostic path

This variant names the correction instead of leaving the failure implicit.

space examples/diagnostics/correction

proc safe_index(index: int, size: int) -> int {
  if size <= 0 { give 40 }
  if index < 0 { give 41 }
  if index >= size { give 42 }
  give index
}

proc main(args: list[string]) -> int {
  give safe_index(1, 3)
}

export *

Risks and diagnostics

RiskDiagnostic signalAction
Boundary driftThe chapter loses sight of expected shape, actual shape, and correction path.Restate the boundary beside the first code block and every invalid case.
Generic proseA paragraph would still be true in another chapter.Replace it with a code-specific rule from this page.
Weak diagnosticThe failure does not point back to the chapter contract.Reduce the invalid case until one failure explains the rule.

Review checklist

  • The first example is complete and aligned with Vitte docs syntax.
  • The production section names where this construct belongs in real code.
  • The risk table connects each failure to a diagnostic or review action.
  • The avoid list rejects broad misuse without adding quiz-like prompts.

Production use

  • Use this chapter when a code review needs to preserve expected shape, actual shape, and correction path.
  • Keep examples small enough to copy into fixtures or docs smoke tests.
  • Treat the invalid case as regression material for future docs checks.

What to avoid

  • Do not add a second topic that hides the chapter's main contract.
  • Do not expand examples by adding unrelated subsystems.
  • Do not rely on prose when a small Vitte block can show the rule.

Global explanation

A diagnostics chapter should explain the shape of a failure: what contract was expected, which surface broke it, and how to return to a valid program. The message is a pointer back to structure, not an isolated artifact.

Invalid case

proc bad_div(total: int, count: int) -> int {
  if count { give total }
  give 0
}

This invalid case stays small so the broken contract remains visible.

Common pitfalls

  • Teaching diagnostics as a table of codes with no code story.
  • Explaining only the message text, not the broken contract.
  • Using overly large examples that hide the first real mistake.

Short exercise

Take the invalid example and reduce it until one diagnostic still reproduces the same contract failure.

Summary in 5 points

  1. Diagnostics point back to a broken contract.
  2. A valid and invalid pair is the right teaching unit.
  3. Smaller repros are more educational than giant failing files.
  4. The first useful diagnostic move is naming the broken contract.
  5. Actionable fixes start from structure, not from guesswork.

Next best action

Keep the example small, reproduce it locally, then continue to the full chapter if you need the broader context.

Chapter deep dive

31. Build errors links compiler messages back to broken contracts. The chapter is written for a reader learning to reduce an error instead of guessing.

The practical boundary is: expected shape, actual shape, and correction path. Keep that boundary in view while reading the example, the invalid case, and the exercise.

Role in the learning path

Readers often see diagnostics as messages to memorize rather than structured signals tied to a failing contract.

One broken program produces one actionable error, then a corrected version restores the intended flow.

This chapter helps the reader classify and use diagnostics instead of fearing them.

Profile-specific deep dive

Failure shape

  • Start from the expected contract, then show the actual broken shape.
  • Keep the repro small enough that the first diagnostic is credible.
  • Explain the correction as a structural change, not a guess.

Diagnostic reading

  • Parser diagnostics point to shape.
  • Type diagnostics point to contract mismatch.
  • Module diagnostics point to visibility, ownership, or path resolution.

Reading the valid example

  1. space demo/diagnostics: names the ownership boundary before any behavior appears.
  2. proc safe_div(total: int, count: int) -> int {: states the callable contract: inputs first, result shape last.
  3. if count == 0 { give 0 }: guards a failure or edge case before the nominal result.
  4. give total: ends the local path with an explicit result.
  5. }: supports the chapter contract without adding hidden behavior.
  6. export *: supports the chapter contract without adding hidden behavior.

Lesson from the invalid example

  1. proc bad_div(total: int, count: int) -> int {: this line helps isolate the failure because it states the callable contract: inputs first, result shape last.
  2. if count { give total }: this line helps isolate the failure because it guards a failure or edge case before the nominal result.
  3. give 0: this line helps isolate the failure because it ends the local path with an explicit result.
  4. }: this line helps isolate the failure because it supports the chapter contract without adding hidden behavior.

Engineering decisions to preserve

  • Name the boundary before changing code: Diagnostics point back to a broken contract.
  • Keep the smallest example executable: A valid and invalid pair is the right teaching unit.
  • Make the invalid path explain one failure only: Smaller repros are more educational than giant failing files.
  • Prefer a visible contract over an implied convention: The first useful diagnostic move is naming the broken contract.
  • Leave a review anchor that another maintainer can verify: Actionable fixes start from structure, not from guesswork.

Context-specific review criteria

  • The page makes the expected shape, actual shape, and correction path boundary visible before the first code block.
  • The intended reader, a reader learning to reduce an error instead of guessing, can follow the valid example through named contracts instead of memorized tokens.
  • The invalid example fails for the same reason the prose discusses.
  • The exercise extends the same contract instead of introducing an unrelated concept.
  • The next chapter can reuse the vocabulary introduced here without redefining it.
  • The chapter stays specific enough that its title materially changes the meaning of the page.
  • Every warning connects to a concrete code shape.
  • The summary leaves one durable engineering rule behind.

Contract matrix

ConcernChapter ruleEvidence to keep
OwnershipCode belongs behind the boundary named by the chapter.The chapter keeps ownership visible through expected shape, actual shape, and correction path.
Input contractThe procedure receives a shape that is named before branching.The valid example names the accepted shape before branching.
Nominal pathThe clean path remains readable without hidden state.The successful result can be found without reading hidden state.
Failure pathThe invalid case isolates one failure reason.The broken example has one main reason to fail.
NamingNames explain the domain rather than only the mechanism.Names remain tied to the chapter goal.
TypesTypes remove ambiguity from values and results.Fields and return values carry domain meaning.
Control flowBranches stay traceable from guard to result.Guards appear before the result they protect.
Module boundaryThe public surface stays smaller than implementation detail.The public surface remains smaller than the implementation detail.
Diagnostic valueThe failure path points back to the exact contract.The invalid example points back to the exact contract.
Test valueRegression evidence covers one passing path and one failing path.One passing case and one failing case cover the lesson.
Refactor valueImplementation cleanup preserves the result shape.The result shape stays stable during local cleanup.
Publication valueThe chapter leaves one concrete engineering rule.The chapter leaves one concrete engineering rule.

Rewrite path for this chapter

  1. Rewrite the opening paragraph so it names expected shape, actual shape, and correction path before naming syntax.
  2. Keep the valid example small enough that the full contract fits on screen.
  3. Move any broad claim back to a specific line in the example.
  4. Preserve one invalid case that fails for the chapter's main reason.
  5. Add one sentence explaining why the invalid case is not a random error.
  6. Make every pitfall actionable by naming the code shape it damages.
  7. Keep the exercise inside the same domain as the example.
  8. Avoid introducing a second unrelated project just to show variety.
  9. Use the summary to restate the chapter rule, not the table of contents.
  10. Check that the next chapter can build on this vocabulary.
  11. Remove any sentence that would still be true in every other chapter.
  12. Keep the last action small, local, and testable.

Diagnostic anchors

  • The first inspected line is the one that declares the chapter's main contract.
  • The central type, field, procedure, or branch carries the chapter's main idea.
  • The invalid example includes a sentence-level explanation of its failure.
  • Refactors preserve the detail that would otherwise mislead a future reader.
  • The behavior that must stay stable is named before implementation changes begin.
  • Vague names are replaced before they become review friction.
  • Regression coverage protects the chapter's main contract.
  • Implementation details stay out of public API unless the chapter explicitly teaches that surface.
  • Beginner-facing diagnostics point to the contract, not to a random syntax detail.
  • The next chapter can assume one clearly named concept from this page.

When extending this chapter

  • Extend toward a reader learning to reduce an error instead of guessing, not toward a broader catalog of features.
  • Add a second example only if it sharpens the same contract.
  • Prefer a small variant over a new subsystem.
  • Keep prose close to code; every abstract claim should point to a visible shape.
  • Do not hide a new concept in the exercise.
  • If a paragraph explains policy, add the concrete code boundary it protects.
  • If a paragraph explains syntax, add the semantic reason the syntax matters.
  • If a paragraph explains architecture, identify the owner of each boundary.
  • If a paragraph explains failure, keep the failing line close to the explanation.
  • Stop expanding when the chapter has one complete, testable lesson.

Failure modes to avoid

  • Teaching diagnostics as a table of codes with no code story.
  • Explaining only the message text, not the broken contract.
  • Using overly large examples that hide the first real mistake.

Practice scenario

Start from the coherent example in 31. Build errors. Change one identifier, one guard, and one returned value. After each change, write down whether the public contract is still the same contract or a new one.

If the contract changed, update the type or result shape first. If only the implementation changed, keep the external name stable and add one regression note explaining what should not change again.

Before moving on

  • You can state the chapter role: links compiler messages back to broken contracts.
  • You can point to the main boundary: expected shape, actual shape, and correction path.
  • You can connect the invalid case to the problem statement: Readers often see diagnostics as messages to memorize rather than structured signals tied to a failing contract.
  • You can perform the exercise: Take the invalid example and reduce it until one diagnostic still reproduces the same contract failure.