Skip to content

feat!: add OscalBuilderError and a key for make_resource - #78

Merged
dfkunstler merged 1 commit into
mainfrom
feat/62-builder-error-and-resource-key
Nov 17, 2026
Merged

dfkunstler merged 1 commit into
mainfrom
feat/62-builder-error-and-resource-key

Conversation

@dfkunstler

Copy link
Copy Markdown
Member

Summary

  1. New OscalBuilderError(ValueError). It is not an OscalParseError. Each builder raises it for each invalid input, with errors entries and the ValidationError as __cause__.
  2. make_resource(key=...): a key and no uuid give the UUID version 5 of the key (BMB-004). An empty key, a non-string key, or a key with a uuid raises OscalBuilderError.
  3. The builders validate a JSON-shaped object with one model_validate call, so an item made with model_construct is validated.
  4. make_hash accepts an algorithm string that is not a named algorithm (SHA-999), and rejects SHA-256 (BMB-001).
  5. The conformance runner runs build-hash, build-rlink, and build-resource, and maps the new class to builder-error. 13 expected failures and the xfail of test_every_category_is_mapped are removed.
  6. build-resource/invalid-document-id stays a strict expected failure, now tracked by Post-processor removes pattern= from string fields whose context has the text 'int' #77.
  7. The change is archived, and the error-tests spec has the builder-error category.

BREAKING: code that catches pydantic.ValidationError from a builder must catch OscalBuilderError or ValueError.

Closes #53. Closes #62. Refs #63 (only the facade operation stays open).

Benchmarks (median of 7, Python 3.14.8, pydantic 2.14.2)

The change does not touch these paths. The unchanged pydantic_core.to_json row moved about 3%, like the others, so I read it as run-to-run noise. PERFORMANCE.md is unchanged.

Path Before, GC on ms Before, GC off ms After, GC on ms After, GC off ms
parse_oscal(bytes) 62.3 46.1 68.0 48.0
serialize_oscal(doc, indent=None) 133.7 128.1 141.3 134.3
serialize_oscal(doc) 141.4 134.9 149.4 141.5
doc.model_dump_json() 140.0 133.6 146.8 140.3
pydantic_core.to_json(doc) 143.6 136.5 147.3 140.8

Memory peaks (bench_memory.py) are identical before and after.

Verification

  1. hatch run release passes, and models.py has no drift.
  2. openspec validate add-builder-error-and-resource-key --strict passed before archive.
  3. Conformance: 94 passed, 17 strict expected failures.

The builders validate a JSON-shaped object once and raise
OscalBuilderError (a ValueError, not an OscalParseError) instead of
pydantic.ValidationError. make_resource takes a key that gives the UUID
version 5 identifier. make_hash accepts an algorithm string that is not a
named algorithm. The conformance runner runs the build-hash, build-rlink,
and build-resource operations.

BREAKING CHANGE: code that catches pydantic.ValidationError from a
builder must catch OscalBuilderError or ValueError.

Closes #53
Closes #62
Refs #63
@dfkunstler
dfkunstler merged commit 90b909b into main Nov 17, 2026
12 checks passed
@dfkunstler
dfkunstler deleted the feat/62-builder-error-and-resource-key branch November 17, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant