Skip to content

Add example pair for fail-fast required variables via ${var:?message} (rule 17) #16

Description

@posidoni

Context

reference/shell-standards.md rule 17
("Fail fast on a required variable with ${var:?message}") has no runnable
pair under examples/standards/. Follow the contract
in CONTRIBUTING.md.

Plan

  1. Add examples/standards/13-fail-fast-required-var.good.sh:
    • Guard a required variable with : "${VAR:?message}" before using it in
      a path or command, so a missing/empty value aborts immediately with a
      clear message on stderr.
    • Self-contained (set the variable directly in the script so it runs to
      completion), no arguments, exits 0, clean under
      shellcheck --severity=warning and shfmt. Use mktemp -d + a trap
      for any filesystem work.
  2. Add examples/standards/13-fail-fast-required-var.bad.sh:
    • Use the same variable unchecked (e.g. leave it defaulted to empty via
      : "${VAR:=}") so an empty value silently builds a broken path instead
      of failing.
    • Safe to run — keep every path inside the mktemp -d sandbox so an empty
      variable can never touch anything outside it.
      # expect-shellcheck: none — this is a style-guide-only pitfall,
      ShellCheck cannot detect a missing fail-fast check.
  3. Add a row to the table in examples/standards/README.md.

Verify

task ci

must stay green.

A small ask

If you used an AI coding agent for this PR, feel free to say so — add a line
to the PR description like:

Authored by <your name/handle>, implemented using <model name>.

Either way is genuinely welcome here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions