Files
reverse-engineering-anything/src/application/AnalysisInput.ts
T
morluto 2826592759 refactor(application): build application cancellations with a required reason (#10574)
* refactor(application): build application cancellations with a required reason

Migrate every AnalysisCancelledError construction under src/application
to cancelledBy and lower the guard baseline from 671 to 442.

Shutdown refusals in BinarySession report OwnerCancellation.ownerClosed
when the caller did not abort, instead of an undefined reason.
ReverseEngineeringService and DesktopBuildOwnedWork close their work
with the typed owner reason. SharedStartupAttempt returns the departing
caller's reason with a cancelled wait. One shared isAborted predicate
replaces eleven local copies and narrows a checked signal for
cancelledBy.

* refactor(desktop): drop an unused cancellation import from desktop capture state
2026-11-15 18:38:24 +08:00

24 lines
860 B
TypeScript

import type { z } from "zod";
import type { AnalysisError } from "../domain/analysisErrorBase.js";
import { cancelledBy } from "../domain/analysisErrorCore.js";
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
import { err, ok, type Result } from "../domain/result.js";
/** Validate an application request, honoring cancellation before admission when supplied. */
export const parseAnalysisInput = <T>(
operation: string,
rawInput: unknown,
schema: z.ZodType<T>,
signal?: AbortSignal,
): Result<T, AnalysisError> => {
if (signal?.aborted) return err(cancelledBy(operation, signal));
const input = schema.safeParse(rawInput);
if (!input.success)
return err(
analysisInputErrorFromIssues(operation, input.error.issues, rawInput, {
cause: input.error,
}),
);
return ok(input.data);
};