mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
ArtifactReaderFailure("format") covered two different facts: target
bytes that violate their format, and a selected path that is not a
regular file. The shared selected-file projections
(projectOwnedArtifactInputFailure and classifyProviderFailure's file
step) mapped both to invalid_request with an invalid_format path
issue, so corrupt BEAM files and PE certificate table bodies were
reported as caller argument errors.
Split the reason at its producers:
- Path-kind refusals now use the existing "path" selection reason:
regular-file admission, the stable root, directory, ZIP, ASAR and
PyInstaller entries, dyld inputs, the UEFI flash source and extract
occurrence selection. They stay invalid_request.
- The BEAM parser and the PE certificate table parser raise the format
owner's ParseFailureError (malformed or truncated, format "beam" or
"pe-certificate-table"). A short file that does not start with FOR1
is malformed, not truncated. A PKCS#7 name encoding the decoder does
not implement is unsupported, not malformed.
- Short reads inside an admitted range (kernel module, kernel build
config, ELF unwind ranges) are integrity read-coverage failures,
because the file changed during the read.
- Internal contract breaks (stream chunk size, a non-Buffer keyed
archive chunk) are invariant violations; an impossible descriptor
byte count is an I/O failure.
The shared projections now treat only "path" as a selection error.
They take the malformed-target facts from the reader failure's own
parseFailure, which artifactParseFailure sets once from the owner's
ParseFailureError and rebuilt failures keep through primaryFacts.
ArtifactOperationError carries the same facts, so inspect_artifact
refusals (for example Android boot images) now include
details.format_failure, format, offset and field. Android boot entry
planning raises the format owner's malformed failure, and the
redundant shortcut and API-contract format branches are removed.
BREAKING CHANGE: callers that parse `code` see unsupported_target
instead of invalid_request for malformed or truncated bytes from
inspect_erlang_beam and from the inspect_pe_certificates certificate
table body. Truncated reads of a file that changed during
inspect_kernel_module, inspect_kernel_build_config and
inspect_elf_unwind_ranges now report artifact_changed. inspect_artifact
malformed and truncated refusals gain details.format_failure and
details.format. Existing fields are unchanged.
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import {
|
|
NonRegularFileReadError,
|
|
RegularFileAdmissionFailure,
|
|
RegularFileChangedError,
|
|
RegularFileOperationCancelled,
|
|
} from "../filesystem/RegularFile.js";
|
|
import { ArtifactReaderFailure } from "./ArtifactReader.js";
|
|
|
|
/** Project physical admission failures without taking the caller's descriptor ownership. */
|
|
export const artifactFileAdmissionFailure = (
|
|
path: string,
|
|
diagnosticLabel: string,
|
|
cause: unknown,
|
|
): ArtifactReaderFailure => {
|
|
if (cause instanceof ArtifactReaderFailure) return cause;
|
|
if (cause instanceof RegularFileOperationCancelled)
|
|
return new ArtifactReaderFailure(
|
|
"cancelled",
|
|
`${diagnosticLabel} admission cancelled`,
|
|
{ cause: cause.reason },
|
|
);
|
|
if (cause instanceof RegularFileAdmissionFailure)
|
|
return ArtifactReaderFailure.withCleanup(
|
|
artifactFileAdmissionFailure(path, diagnosticLabel, cause.cause),
|
|
ArtifactReaderFailure.cleanupObservation(cause.cleanupCause, path),
|
|
);
|
|
if (cause instanceof RegularFileChangedError)
|
|
return new ArtifactReaderFailure(
|
|
"integrity",
|
|
`${diagnosticLabel} source changed during admission: ${path}`,
|
|
{ cause, integrityCheck: "container-identity" },
|
|
);
|
|
if (cause instanceof NonRegularFileReadError)
|
|
return new ArtifactReaderFailure(
|
|
"path",
|
|
`${diagnosticLabel} source is not a regular file: ${path}`,
|
|
{ cause },
|
|
);
|
|
return new ArtifactReaderFailure(
|
|
"io",
|
|
cause instanceof Error
|
|
? cause.message
|
|
: `Cannot admit ${diagnosticLabel} source: ${path}`,
|
|
{ cause },
|
|
);
|
|
};
|