Skip to content

feat!: add error category classes and the limit property - #74

Merged
dfkunstler merged 1 commit into
mainfrom
feat/error-category-tree-and-limit
Nov 17, 2026
Merged

dfkunstler merged 1 commit into
mainfrom
feat/error-category-tree-and-limit

Conversation

@dfkunstler

Copy link
Copy Markdown
Member

Closes #60

Changes

  1. OscalDocumentTypeMismatchError(OscalParseError): the eight typed parsers raise it for a document of another type. The message is unchanged.
  2. OscalUnknownElementTypeError(Exception): validate_element raises it for an element type that the library does not recognize.
  3. OscalParseError.limit: the identifier of the documented limit that stopped the parse (json_depth, json_digits, yaml_alias_nodes, yaml_alias_characters, yaml_depth, yaml_line_break_placeholders), else None. Entry types are unchanged.
  4. The conformance runner reads the error class only, not the message text.
  5. README, AGENTS.md, and .agents/summary/ updated. The change is archived and error-tests is added to the main specs.

Breaking change

validate_element no longer raises OscalParseError for an unrecognized element type. It raises OscalUnknownElementTypeError, which is not a subclass of OscalParseError (ERR-008, ERR-009). Code that catches OscalParseError around validate_element for this case must catch the new class.

Benchmarks (median of 7, GC on / GC off, ms)

Path main after, run 1 after, run 2
parse_oscal(bytes) 59.1 / 43.6 58.2 / 43.0 58.9 / 43.8
serialize_oscal(doc, indent=None) 126.8 / 119.8 126.9 / 120.3 129.4 / 123.1
serialize_oscal(doc) 134.2 / 127.9 134.0 / 129.3 136.8 / 131.1
doc.model_dump_json() 133.5 / 126.1 132.9 / 127.1 141.2 / 134.7
pydantic_core.to_json(doc) 133.7 / 127.8 134.3 / 127.6 140.3 / 133.5

Memory (peak MB) is identical: 36.5, 84.3, 144.4, 146.4. No median moves more than the run-to-run spread.

hatch run release passes.

Add OscalDocumentTypeMismatchError (a subclass of OscalParseError) for the
typed parsers, and OscalUnknownElementTypeError for validate_element. Add
OscalParseError.limit, which names the documented limit that stopped a parse
(ERR-009, ERR-010). The conformance runner now reads the error class only.

BREAKING CHANGE: validate_element raises OscalUnknownElementTypeError, not
OscalParseError, for an element type that the library does not recognize.

Closes #60
@dfkunstler
dfkunstler merged commit f6a4657 into main Nov 17, 2026
6 checks passed
@dfkunstler
dfkunstler deleted the feat/error-category-tree-and-limit branch November 17, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the limit of a parse error testable (ERR-010)

1 participant