feat(errors): add caller-safe typed error projections
This commit is contained in:
+39
-9
@@ -36,7 +36,7 @@ describe("analysis error projection", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("exhaustively projects stable tags without causes or local paths", () => {
|
||||
it("projects every typed failure without internal details", () => {
|
||||
const secretCause = new Error("secret-token");
|
||||
const byTag = {
|
||||
AnalysisProtocolError: new AnalysisProtocolError("protocol failed"),
|
||||
@@ -97,17 +97,47 @@ describe("analysis error projection", () => {
|
||||
} satisfies Readonly<Record<AnalysisErrorTag, AnalysisError>>;
|
||||
const errors = Object.values(byTag);
|
||||
const projected = errors.map(projectAnalysisError);
|
||||
expect(new Set(projected.map(({ tag }) => tag)).size).toBe(errors.length);
|
||||
expect(projected).toHaveLength(23);
|
||||
expect(JSON.stringify(projected)).not.toContain("secret-token");
|
||||
expect(JSON.stringify(projected)).not.toContain("/secret/local/path");
|
||||
const serialized = JSON.stringify(projected);
|
||||
for (const hidden of ["secret-token", "/secret/local/path"])
|
||||
expect(serialized).not.toContain(hidden);
|
||||
expect(
|
||||
projected.find(({ tag }) => tag === "HopperTimeoutError"),
|
||||
).toMatchObject({ details: { timeoutMs: 100 } });
|
||||
expect(
|
||||
projected.find(({ tag }) => tag === "ProviderAdapterError"),
|
||||
projectAnalysisError(byTag.AnalysisCapabilityUnavailableError),
|
||||
).toMatchObject({
|
||||
details: { providerId: "fixture", operation: "overview" },
|
||||
tag: "AnalysisCapabilityUnavailableError",
|
||||
category: "unsupported_provider",
|
||||
details: {
|
||||
providerId: "fixture",
|
||||
operation: "overview",
|
||||
reason: "absent",
|
||||
},
|
||||
});
|
||||
expect(
|
||||
projectAnalysisError(
|
||||
new ArtifactOperationError("inventory_artifact", "integrity", {
|
||||
logicalPath: "main.js",
|
||||
declaredSha256: "a".repeat(64),
|
||||
calculatedSha256: "b".repeat(64),
|
||||
unpacked: true,
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
tag: "ArtifactOperationError",
|
||||
category: "integrity_mismatch",
|
||||
details: {
|
||||
logicalPath: "main.js",
|
||||
declaredSha256: "a".repeat(64),
|
||||
calculatedSha256: "b".repeat(64),
|
||||
unpacked: true,
|
||||
},
|
||||
});
|
||||
expect(projected.every(({ message }) => message.length > 0)).toBe(true);
|
||||
expect(
|
||||
projected.every(({ message }) =>
|
||||
/try again|run `rea doctor`|current target|when ready|smaller request|smaller artifact|fresh copy|re-import|reduce|inline evidence|configured evidence directory|evidence file|allow overwrite|refresh the current state|reported setting|call open_binary|supported file|review capture policy/u.test(
|
||||
message,
|
||||
),
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user