Skip to content

Error Conditions ​

This document specifies the conditions that MUST produce errors during beancount processing.

Error Structure ​

All errors MUST include:

FieldDescription
LocationFile path and line number where the error occurred
MessageHuman-readable description of the error
ContextThe directive that caused the error (when applicable)

Error Categories ​

Lexical Errors ​

Errors during tokenization:

ConditionDescription
Invalid tokenUnrecognized character sequence
Unterminated stringString literal without closing quote
Invalid date formatDate not matching YYYY-MM-DD or YYYY/MM/DD

Syntax Errors ​

Errors during parsing:

ConditionDescription
Malformed directiveDirective structure doesn't match grammar
Unknown directiveUnrecognized directive keyword
Missing required fieldRequired component missing from directive
Invalid optionUnknown option name
Invalid option valueOption value doesn't match expected format

Semantic Errors ​

Errors during validation:

ConditionDescription
Account not openedPosting references account without prior open
Duplicate openSame account opened twice without intervening close
Posting after closePosting references account after its close date
Currency constraintPosting uses currency not allowed by account's open
Transaction imbalanceSum of posting weights doesn't equal zero (within tolerance)
Duplicate metadataSame metadata key appears twice on one directive

Balance Errors ​

Errors during balance assertion processing:

ConditionDescription
Assertion failedActual balance doesn't match expected (outside tolerance)

Booking Errors ​

Errors during lot matching and booking:

ConditionDescription
No matching lotReduction cost specification doesn't match any existing lot
Insufficient unitsNot enough units in matched lots to fulfill reduction
Ambiguous matchMultiple lots match in STRICT mode without disambiguation
Elision ambiguityMultiple postings with missing amounts (see elision rules)

Pad Errors ​

Errors during pad directive processing:

ConditionDescription
Unused padPad directive without subsequent balance directive
Zero adjustmentPad produces no change (balance already matches)

Document Errors ​

Errors during document directive processing:

ConditionDescription
File not foundDocument path references non-existent file

Error Severity ​

All conditions listed above are errors that MUST be reported. Implementations MAY also provide:

  • Warnings - Non-fatal issues that don't prevent processing
  • Info - Informational messages about processing

Error Recovery ​

Implementations SHOULD continue processing after encountering errors when possible, to report multiple errors in a single pass. However, some errors (like severe syntax errors) may prevent further processing.

Error Reporting ​

Required Information ​

Error output MUST include:

  • File path where error occurred
  • Line number where error occurred
  • Clear description of the problem

Error output SHOULD include:

  • Column number (for syntax errors)
  • The offending text/token
  • Suggestion for how to fix the issue

Machine-Readable Output ​

Implementations SHOULD support machine-readable error output (e.g., JSON) for tooling integration.

Processing Order ​

Errors are detected in the following order:

  1. Lexical - During tokenization
  2. Syntax - During parsing
  3. Semantic - During validation (account references, currencies)
  4. Booking - During lot matching and interpolation
  5. Balance - During balance assertion checking
  6. Document - During document file verification