mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 05:51:06 +00:00
refactor(providers): share the offline adapter error fallback (#14466)
This commit is contained in:
1 parent
6c51be5317
commit
2c847e767c
11 files changed
+31
-128
No files matched your search
@@ -32,7 +32,6 @@ import {
|
||||
type GoStringLiterals,
|
||||
type InspectGoBinaryInput,
|
||||
} from "../domain/go/goBinary.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import { fixedAllowanceOptions } from "../domain/fixedAllowanceRemediation.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import {
|
||||
@@ -44,7 +43,6 @@ import {
|
||||
BinaryResourceFailure,
|
||||
binaryResourceCeiling,
|
||||
} from "../domain/binaryContainer.js";
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "inspect_go_binary";
|
||||
const HEADER_PREFIX_BYTES = 4096;
|
||||
@@ -143,14 +141,6 @@ const failureFor = (
|
||||
);
|
||||
return undefined;
|
||||
},
|
||||
unclassified: (failure) =>
|
||||
new ProviderAdapterError(GO_BINARY_PROVIDER_IDENTITY.id, OPERATION, {
|
||||
cause: failure,
|
||||
diagnostics: {
|
||||
path,
|
||||
reason: errorMessage(failure),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
if (completed !== undefined) primary.retainPartialObservation(completed);
|
||||
|
||||
@@ -118,7 +118,6 @@ const mavenGradleMetadataFailure = (
|
||||
providerId: MAVEN_GRADLE_METADATA_PROVIDER_IDENTITY.id,
|
||||
path: input.path,
|
||||
description: "Maven POM or Gradle module metadata",
|
||||
fallbackMessage: "Maven/Gradle metadata inspection failed.",
|
||||
recognise: (failure) => {
|
||||
if (!isParseLimit(failure, MAVEN_GRADLE_METADATA_FORMAT))
|
||||
return undefined;
|
||||
|
||||
@@ -35,7 +35,6 @@ import { classifyProviderFailure } from "../../providers/classifyProviderFailure
|
||||
import { offlineArtifactFailureDialect } from "../../providers/offlineArtifactFailure.js";
|
||||
import type { LimitRef } from "../../domain/parseFailure.js";
|
||||
import { fixedAllowanceOptions } from "../../domain/fixedAllowanceRemediation.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import { err, ok } from "../../domain/result.js";
|
||||
import { APPLE_IPS_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import {
|
||||
@@ -45,7 +44,6 @@ import {
|
||||
} from "./AppleIps.errors.js";
|
||||
import { parseAppleIps } from "./AppleIpsParser.js";
|
||||
import { resolveAppleIpsJoin } from "./AppleIpsMachOJoin.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "inspect_apple_ips";
|
||||
|
||||
@@ -322,13 +320,5 @@ const appleIpsFailurePrimary = (
|
||||
remediationAction: fileSizeRemediation(input, field),
|
||||
},
|
||||
),
|
||||
unclassified: (failure) =>
|
||||
new ProviderAdapterError(APPLE_IPS_PROVIDER.id, OPERATION, {
|
||||
cause: failure,
|
||||
diagnostics: {
|
||||
path: input.path,
|
||||
reason: errorMessage(failure),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
@@ -24,7 +24,6 @@ import {
|
||||
MAX_INSPECT_NATIVE_EXPORTS_FILE_BYTES,
|
||||
type InspectNativeExportsInput,
|
||||
} from "../../domain/native/nativeExports.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import { err, ok } from "../../domain/result.js";
|
||||
import { NATIVE_EXPORTS_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import {
|
||||
@@ -37,7 +36,6 @@ import {
|
||||
type NativeExportLimit,
|
||||
parseNativeExportsFromHandle,
|
||||
} from "../../domain/native/nativeExportParser.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "inspect_native_exports";
|
||||
const HEADER_PREFIX_BYTES = 4096;
|
||||
@@ -164,14 +162,6 @@ const nativeExportsFailure = (
|
||||
max_file_bytes: input.max_file_bytes,
|
||||
},
|
||||
),
|
||||
unclassified: (failure) =>
|
||||
new ProviderAdapterError(NATIVE_EXPORTS_PROVIDER.id, OPERATION, {
|
||||
cause: failure,
|
||||
diagnostics: {
|
||||
path: input.path,
|
||||
reason: errorMessage(failure),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
return projectStableArtifactFailure(
|
||||
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
MAX_INSPECT_BINARY_HARDENING_FILE_BYTES,
|
||||
type InspectBinaryHardeningInput,
|
||||
} from "../../domain/native/binaryHardening.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import { err, ok } from "../../domain/result.js";
|
||||
import { BINARY_HARDENING_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import {
|
||||
@@ -34,7 +33,6 @@ import {
|
||||
import { readElfHardeningFromHandle } from "./ElfHardening.js";
|
||||
import { readMachoHardeningFromHandle } from "./MachoHardening.js";
|
||||
import { readPeHardeningFromHandle } from "./PeHardening.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "inspect_binary_hardening";
|
||||
const HEADER_PREFIX_BYTES = 4096;
|
||||
@@ -170,14 +168,6 @@ const binaryHardeningFailure = (
|
||||
max_file_bytes: input.max_file_bytes,
|
||||
},
|
||||
),
|
||||
unclassified: (failure) =>
|
||||
new ProviderAdapterError(BINARY_HARDENING_PROVIDER.id, OPERATION, {
|
||||
cause: failure,
|
||||
diagnostics: {
|
||||
path: input.path,
|
||||
reason: errorMessage(failure),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
return projectStableArtifactFailure(
|
||||
|
||||
@@ -33,7 +33,6 @@ import {
|
||||
type NativeInitializers,
|
||||
type NativeInitializerSlice,
|
||||
} from "../../domain/native/nativeInitializers.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import { err, ok } from "../../domain/result.js";
|
||||
import { NATIVE_INITIALIZERS_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import {
|
||||
@@ -44,7 +43,6 @@ import { hasMachoMagic } from "../../domain/apple/machoContainer.js";
|
||||
import { requireSelectedNativeImage } from "../../domain/apple/machoSliceSelection.js";
|
||||
import { readElfInitializers } from "./ElfInitializers.js";
|
||||
import { readMachoInitializers } from "./MachoInitializers.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "inspect_native_initializers";
|
||||
|
||||
@@ -232,14 +230,6 @@ const nativeInitializersFailure = (
|
||||
);
|
||||
return undefined;
|
||||
},
|
||||
unclassified: (failure) =>
|
||||
new ProviderAdapterError(NATIVE_INITIALIZERS_PROVIDER.id, OPERATION, {
|
||||
cause: failure,
|
||||
diagnostics: {
|
||||
path: input.path,
|
||||
reason: errorMessage(failure),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
return projectStableArtifactFailure(
|
||||
|
||||
@@ -11,7 +11,6 @@ import type {
|
||||
AnalysisPartialObservation,
|
||||
} from "../../domain/analysisErrorBase.js";
|
||||
import type { ResourceConstraintRecovery } from "../../domain/analysisErrorCore.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import {
|
||||
BinaryResourceFailure,
|
||||
binaryResourceCeiling,
|
||||
@@ -19,7 +18,6 @@ import {
|
||||
} from "../../domain/binaryContainer.js";
|
||||
import { classifyProviderFailure } from "../../providers/classifyProviderFailure.js";
|
||||
import { offlineArtifactFailureDialect } from "../../providers/offlineArtifactFailure.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
interface PeBinaryInput {
|
||||
readonly path: string;
|
||||
@@ -75,14 +73,6 @@ export const projectPeBinaryFailure = <Limit extends string>(
|
||||
artifactFileCeilingConstraint(operation, failure, options.fileCeiling, {
|
||||
max_file_bytes: input.max_file_bytes,
|
||||
}),
|
||||
unclassified: (failure) =>
|
||||
new ProviderAdapterError(providerId, operation, {
|
||||
cause: failure,
|
||||
diagnostics: {
|
||||
path: input.path,
|
||||
reason: errorMessage(failure),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
if (options.completed !== undefined)
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
MAX_INSPECT_WINDOWS_SHORTCUT_STRING_BYTES,
|
||||
type InspectWindowsShortcutInput,
|
||||
} from "../../domain/native/windowsShortcut.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import { err, ok } from "../../domain/result.js";
|
||||
import { WINDOWS_SHORTCUT_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import { classifyProviderFailure } from "../../providers/classifyProviderFailure.js";
|
||||
@@ -36,7 +35,6 @@ import {
|
||||
type WindowsShortcutSelectedBoundary,
|
||||
} from "./WindowsShortcut.errors.js";
|
||||
import { parseWindowsShortcut } from "./WindowsShortcutParser.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "inspect_windows_shortcut";
|
||||
|
||||
@@ -297,14 +295,6 @@ const windowsShortcutFailure = (
|
||||
remediationAction: fileSizeRemediation(input),
|
||||
},
|
||||
),
|
||||
unclassified: (failure) =>
|
||||
new ProviderAdapterError(WINDOWS_SHORTCUT_PROVIDER.id, OPERATION, {
|
||||
cause: failure,
|
||||
diagnostics: {
|
||||
path: input.path,
|
||||
reason: errorMessage(failure),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
return projectStableArtifactFailure(
|
||||
|
||||
@@ -5,6 +5,8 @@ import {
|
||||
artifactOperationReason,
|
||||
} from "../resources/index.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
import { ArtifactOperationError } from "../domain/artifactOperationError.js";
|
||||
import { parseFailureAnalysisError } from "../domain/parseFailureAnalysisError.js";
|
||||
import type { ProviderFailureDialect } from "./classifyProviderFailure.js";
|
||||
@@ -13,7 +15,7 @@ type ArtifactOperation = ConstructorParameters<
|
||||
typeof ArtifactOperationError
|
||||
>[0];
|
||||
|
||||
interface OfflineArtifactDialectBase {
|
||||
export type OfflineArtifactDialectOptions = {
|
||||
readonly providerId: string;
|
||||
readonly path: string;
|
||||
readonly description: string;
|
||||
@@ -29,25 +31,15 @@ interface OfflineArtifactDialectBase {
|
||||
) => AnalysisError | undefined;
|
||||
/** Projection for a selected file exceeding the caller's `file-size` budget. */
|
||||
readonly fileSize?: (cause: ArtifactReaderFailure) => AnalysisError;
|
||||
}
|
||||
|
||||
export type OfflineArtifactDialectOptions =
|
||||
| (OfflineArtifactDialectBase & {
|
||||
readonly operation: ArtifactOperation;
|
||||
readonly fallbackMessage: string;
|
||||
readonly unclassified?: (
|
||||
cause: unknown,
|
||||
origin: ArtifactFilePrimaryFacts["origin"],
|
||||
) => AnalysisError;
|
||||
})
|
||||
| (OfflineArtifactDialectBase & {
|
||||
readonly operation: string;
|
||||
readonly fallbackMessage?: never;
|
||||
readonly unclassified: (
|
||||
cause: unknown,
|
||||
origin: ArtifactFilePrimaryFacts["origin"],
|
||||
) => AnalysisError;
|
||||
});
|
||||
/** A provider-specific projection for failures outside the shared file and parser cases. */
|
||||
readonly unclassified?: (
|
||||
cause: unknown,
|
||||
origin: ArtifactFilePrimaryFacts["origin"],
|
||||
) => AnalysisError;
|
||||
} & (
|
||||
| { readonly operation: ArtifactOperation; readonly fallbackMessage: string }
|
||||
| { readonly operation: string; readonly fallbackMessage?: never }
|
||||
);
|
||||
|
||||
/**
|
||||
* Shared `ProviderFailureDialect` for offline single-file artifact providers:
|
||||
@@ -80,22 +72,24 @@ export const offlineArtifactFailureDialect = (
|
||||
...(field === undefined ? {} : { field }),
|
||||
...(options.fileSize === undefined ? {} : { fileSize: options.fileSize }),
|
||||
},
|
||||
unclassified: (failure) =>
|
||||
options.fallbackMessage === undefined
|
||||
? options.unclassified(failure, origin)
|
||||
: options.unclassified !== undefined
|
||||
? options.unclassified(failure, origin)
|
||||
: new ArtifactOperationError(
|
||||
options.operation,
|
||||
origin === "owned-or-classified" &&
|
||||
failure instanceof ArtifactReaderFailure
|
||||
? artifactOperationReason(failure)
|
||||
: "io",
|
||||
undefined,
|
||||
failure instanceof Error
|
||||
? failure.message
|
||||
: options.fallbackMessage,
|
||||
{ cause: failure },
|
||||
),
|
||||
unclassified: (failure) => {
|
||||
if (options.unclassified !== undefined)
|
||||
return options.unclassified(failure, origin);
|
||||
if (options.fallbackMessage !== undefined)
|
||||
return new ArtifactOperationError(
|
||||
options.operation,
|
||||
origin === "owned-or-classified" &&
|
||||
failure instanceof ArtifactReaderFailure
|
||||
? artifactOperationReason(failure)
|
||||
: "io",
|
||||
undefined,
|
||||
failure instanceof Error ? failure.message : options.fallbackMessage,
|
||||
{ cause: failure },
|
||||
);
|
||||
return new ProviderAdapterError(providerId, operation, {
|
||||
cause: failure,
|
||||
diagnostics: { path, reason: errorMessage(failure) },
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -15,7 +15,6 @@ import {
|
||||
type InspectPythonPycInput,
|
||||
type PythonPycLimits,
|
||||
} from "../domain/python/pythonPyc.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import { err, ok } from "../domain/result.js";
|
||||
import {
|
||||
PYTHON_PYC_FORMAT,
|
||||
@@ -26,7 +25,6 @@ import {
|
||||
parseLimitConstraint,
|
||||
} from "../domain/parseFailureAnalysisError.js";
|
||||
import { parsePythonPyc } from "./PythonPycParser.js";
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
import { classifyProviderFailure } from "../providers/classifyProviderFailure.js";
|
||||
import { offlineArtifactFailureDialect } from "../providers/offlineArtifactFailure.js";
|
||||
|
||||
@@ -86,14 +84,6 @@ const failureFor = (
|
||||
...parserLimitRecovery(input, ["max_file_bytes"]),
|
||||
},
|
||||
),
|
||||
unclassified: (failure) =>
|
||||
new ProviderAdapterError(PYTHON_PYC_PROVIDER_IDENTITY.id, OPERATION, {
|
||||
cause: failure,
|
||||
diagnostics: {
|
||||
path: input.path,
|
||||
reason: errorMessage(failure),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
),
|
||||
input.path,
|
||||
|
||||
@@ -28,7 +28,6 @@ import {
|
||||
type RustBinary,
|
||||
} from "../domain/rust/rustBinary.js";
|
||||
import { fixedAllowanceOptions } from "../domain/fixedAllowanceRemediation.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import {
|
||||
readRustBinaryImageFromHandle,
|
||||
@@ -56,7 +55,6 @@ import {
|
||||
type RustProducerLimits,
|
||||
} from "../domain/rust/rustResourceLimits.js";
|
||||
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "inspect_rust_binary";
|
||||
const HEADER_PREFIX_BYTES = 4096;
|
||||
@@ -459,14 +457,6 @@ const failureFor = (
|
||||
);
|
||||
return undefined;
|
||||
},
|
||||
unclassified: (failure) =>
|
||||
new ProviderAdapterError(RUST_BINARY_PROVIDER_IDENTITY.id, OPERATION, {
|
||||
cause: failure,
|
||||
diagnostics: {
|
||||
path,
|
||||
reason: errorMessage(failure),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
if (completed !== undefined) primary.retainPartialObservation(completed);
|
||||
|
||||
Reference in new issue
Block a user