Repository navigation
feat!: report a read error for a file path that cannot be read - #76
Merged
Merged
Conversation
Add OscalReadError, a subclass of OSError. A file-path parse (parse_oscal_file, parse_oscal_yaml_file, OscalDoc.from_file) raises it for each read failure that is not a missing path (ERR-012): a directory, a permission failure, a loop of symbolic links, an I/O error. The read itself finds the category, with no Path.exists() call, so the category no longer changes with the Python version and the check no longer races the read. FileNotFoundError is raised only for ENOENT, ENOTDIR, or a path the operating system cannot represent. The conformance runner maps OscalReadError to read-error, and the corpus case parse-file/directory passes. BREAKING CHANGE: a file-path parse raises OscalReadError, not OscalParseError, for a read failure. except OSError catches both OscalReadError and FileNotFoundError. Closes #61
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #61
What
A file-path parse (
parse_oscal_file,parse_oscal_yaml_file,OscalDoc.from_file) now meets ERR-012 of the spec store.OscalReadError(OSError). It is raised for each read failure that is not a missing path: a directory, a permission failure, a loop of symbolic links, an I/O error. Itserrno,strerror, andfilenamecome from the failure, and its message names the path. It is not a subclass ofOscalParseErroror ofFileNotFoundError._read_oscal_fileno longer callsPath.exists(). The read itself finds the category:ENOENT,ENOTDIR, or aValueError(a path with a NUL byte) givesFileNotFoundError; each otherOSErrorgivesOscalReadError.exists()hides theerrno, and its answer for a non-ENOENTfailure changes with the Python version (3.12:ELOOP/EBADF; 3.14: everyOSError). The single read also removes the race between the check and the read.OscalReadErrortoread-error. The corpus caseparse-file/directorypasses and leaves the expected failures.test_every_category_is_mappedstays a strict xfail, now for builder-error (Derive the resource identifier from a key and report the builder-error category (BMB-004, ERR-013) #62) only.BREAKING
A file-path parse raises
OscalReadError, notOscalParseError, for a read failure.except OSErrorcatches bothOscalReadErrorandFileNotFoundError.Tests
tests/test_parser.py: directory, file with mode0o000, loop of symbolic links, file in a directory with mode0o000(these permission tests skip as root),ENOTDIR, and a NUL byte.tests/test_yaml_io.py: a directory raisesOscalReadError.hatch run releasepasses: 3398 passed, 2 skipped, 31 xfailed.models.pyhas no drift.Benchmarks
Median of 7 runs, 10.4 MB catalog, Python 3.14.8, GC on / GC off (ms). The change touches only the file-read path, which these scripts do not exercise. The differences are within run-to-run noise.
parse_oscal(bytes)serialize_oscal(indent=None)serialize_oscal()model_dump_json()pydantic_core.to_json(doc)Peak memory is identical (36.5 / 84.3 / 144.4 / 146.4 MB), so
PERFORMANCE.mdneeds no update.OpenSpec
The change
report-read-erroris archived, and its delta is synced intoopenspec/specs/error-tests/spec.md.