Files
rea/src/application/JavaScriptJsonModules.ts
T
morlutoandGitHub 5f27e02fae refactor(runtime): name all silent catch causes without changing diagnostics (#637)
* refactor(domain): split error taxonomy into thematic modules

Move each error family out of domain/errors.ts into its own module
(base, core, provider selection/adapter, browser observation,
artifact, evidence, unknown registry, hopper, configuration) and
relocate AnalysisErrorProjection to analysisErrorProjection.
Migrate all 162 importers to the owning modules and delete
errors.ts. No re-export shims; behavior is unchanged.

* refactor(runtime): name all silent catch causes without changing diagnostics

Bind cause in every bare catch and unhandled rejection across src/.
Real failures preserve the cause for logging; best-effort cleanup
carries an explicit comment. Caller-visible and Evidence strings are
byte-identical to before.
2026-10-06 05:58:46 +08:00

46 lines
1.4 KiB
TypeScript

import { compareCodePoints } from "../domain/canonicalOrdering.js";
import type { JavaScriptJsonModuleObservation } from "./JavaScriptArtifactAnalysisTypes.js";
import type { JavaScriptArtifactFile } from "./JavaScriptArtifactFiles.js";
/** Parse one approved JSON module without evaluating JavaScript or resolving imports. */
export const analyzeJavaScriptJsonModule = (
file: JavaScriptArtifactFile,
): JavaScriptJsonModuleObservation => {
if (!file.text.included)
return {
path: file.path,
sha256: file.sha256,
status: "unavailable",
top_level_keys: [],
omitted_top_level_keys: null,
limitation: `JSON module text was unavailable: ${file.text.reason}.`,
};
let value: unknown;
try {
value = JSON.parse(file.text.value);
} catch (cause: unknown) {
void cause;
return {
path: file.path,
sha256: file.sha256,
status: "invalid",
top_level_keys: [],
omitted_top_level_keys: 0,
limitation: "JSON module is not valid JSON.",
};
}
const keys =
typeof value === "object" && value !== null && !Array.isArray(value)
? Object.keys(value).sort(compareCodePoints)
: [];
const retained = keys;
return {
path: file.path,
sha256: file.sha256,
status: "included",
top_level_keys: retained,
omitted_top_level_keys: 0,
limitation: null,
};
};