fix(http): return a mapping failure when a feature mapper throws (R-3.5)

The feature binding called mapSuccess/mapProblem without a guard, unlike
V2, mapWithBoundaryRegistry and the RPC mapper. A throwing mapper made
execute() reject, so a command the server had confirmed
(APPLIED_CONFIRMED) was normalized downstream to MAYBE_APPLIED.

Both calls are now wrapped; a throw returns MAPPING_CONTRACT_VIOLATION
(code MAPPING_CONTRACT_VIOLATION, same as V2) with the outcome's effect and
HTTP status.

RED before fix: feature-http-binding.test.ts "returns a mapping failure
with the server effect when mapSuccess/mapProblem throws" (execute rejected
with the mapper TypeError).
Gates: check:architecture, check:types:app, check:types:test, lint,
test:component, test:integration, test:contract, test:reference-feature
pass. test:unit passes except removal-fixture.test.ts (needs generated
artifacts/ release evidence absent in a fresh worktree; unrelated).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 12:25:01 +09:00
co-authored by Claude Opus 5.5
parent 5e62b7e1e5
commit 83cf90ba27
2 changed files with 75 additions and 2 deletions
+24 -2
View File
@@ -295,9 +295,26 @@ function projectExecutionOutcome<WireOutput, Problem, Value>(
| undefined,
outcome: HttpExecutionOutcome<WireOutput, Problem>,
): Result<Value, ApiFailure> {
// A throwing feature mapper is a mapping defect, not a transport failure: it
// must not reject and lose the effect the server already confirmed.
const mapperThrew = (
effect: FailureEffectCertainty,
httpStatus: number,
): Result<Value, ApiFailure> =>
failure(
"MAPPING_CONTRACT_VIOLATION",
operationId,
"MAPPING_CONTRACT_VIOLATION",
{ httpStatus, effect },
);
switch (outcome.kind) {
case "SUCCESS": {
const mapped = mapSuccess(outcome.value);
let mapped: MappingResult<Value>;
try {
mapped = mapSuccess(outcome.value);
} catch {
return mapperThrew(outcome.effect, outcome.metadata.status);
}
return mapped.ok
? Object.freeze({ ok: true as const, value: mapped.value })
: failure(
@@ -308,7 +325,12 @@ function projectExecutionOutcome<WireOutput, Problem, Value>(
);
}
case "PROBLEM": {
const mapped = mapProblem?.(outcome.problem, outcome.metadata);
let mapped: FeatureHttpProblemMapping | undefined;
try {
mapped = mapProblem?.(outcome.problem, outcome.metadata);
} catch {
return mapperThrew(outcome.effect, outcome.metadata.status);
}
return failure(
mapped?.kind ?? kindForStatus(outcome.metadata.status),
operationId,
@@ -219,6 +219,57 @@ describe("feature HTTP binding", () => {
},
);
it.each([
[
"mapSuccess",
Object.freeze({
kind: "SUCCESS" as const,
value: Object.freeze({ id: "resource-1", title: "Reference" }),
metadata: Object.freeze({ status: 201 }),
effect: "APPLIED_CONFIRMED" as const,
}),
],
[
"mapProblem",
Object.freeze({
kind: "PROBLEM" as const,
problem: Object.freeze({ code: "RESOURCE_NAME_EXISTS" }),
metadata: Object.freeze({ status: 409 }),
effect: "APPLIED_CONFIRMED" as const,
}),
],
])(
"returns a mapping failure with the server effect when %s throws",
async (_mapper, outcome) => {
const scripted = scriptedExecutor<ResourceWire, ResourceProblem>(outcome);
const binding = createFeatureHttpBinding(scripted.executor, {
LOAD_RESOURCE: defineFeatureHttpOperation({
contract: LOAD_RESOURCE_CONTRACT,
routeId: "RESOURCE_DETAIL",
mapSuccess(): never {
throw new TypeError("mapper defect");
},
mapProblem(): never {
throw new TypeError("mapper defect");
},
}),
} as const);
const result = await binding.execute("LOAD_RESOURCE", {
resourceId: "resource-1",
});
expect(result).toMatchObject({
ok: false,
error: {
kind: "MAPPING_CONTRACT_VIOLATION",
code: "MAPPING_CONTRACT_VIOLATION",
effect: "APPLIED_CONFIRMED",
},
});
},
);
it("lets the feature interpret a typed business problem", async () => {
const scripted = scriptedExecutor<ResourceWire, ResourceProblem>(
Object.freeze({