fix(process): preserve observations after successful cleanup
This commit is contained in:
@@ -393,16 +393,27 @@ const lifecycleErrorDetails = (
|
||||
),
|
||||
}),
|
||||
};
|
||||
if (
|
||||
error._tag === "ProcessCaptureError" &&
|
||||
error.userCategory === "cancelled"
|
||||
)
|
||||
return { operation: "process_capture", cleanup: "complete" };
|
||||
if (
|
||||
error._tag === "ProcessCaptureError" &&
|
||||
error.executionFailure !== undefined
|
||||
)
|
||||
return { execution_failure: error.executionFailure };
|
||||
if (error._tag === "ProcessCaptureError") {
|
||||
const details = {
|
||||
...(error.userCategory === "cancelled"
|
||||
? { operation: "process_capture", cleanup: "complete" }
|
||||
: {}),
|
||||
...(error.cleanupReport === undefined
|
||||
? {}
|
||||
: { cleanup_report: jsonValueSchema.parse(error.cleanupReport) }),
|
||||
...(error.executionFailure === undefined
|
||||
? {}
|
||||
: { execution_failure: error.executionFailure }),
|
||||
...(error.partialObservation === undefined
|
||||
? {}
|
||||
: {
|
||||
partial_observation: jsonValueSchema.parse(
|
||||
error.partialObservation,
|
||||
),
|
||||
}),
|
||||
};
|
||||
return Object.keys(details).length === 0 ? undefined : details;
|
||||
}
|
||||
if (error instanceof BinaryTargetError)
|
||||
return {
|
||||
path: error.path,
|
||||
|
||||
@@ -578,7 +578,7 @@ const incompleteCaptureObservationSchema = z.strictObject({
|
||||
observations: incompleteProcessCaptureObservationsSchema,
|
||||
});
|
||||
|
||||
/** Validated, non-comparable process observations attached to cleanup errors. */
|
||||
/** Validated, non-comparable process observations attached to execution or cleanup errors. */
|
||||
export const partialProcessCaptureObservationSchema = z
|
||||
.union([
|
||||
completedCaptureObservationSchema.extend(
|
||||
@@ -589,15 +589,15 @@ export const partialProcessCaptureObservationSchema = z
|
||||
),
|
||||
])
|
||||
.superRefine((partial, context) => {
|
||||
if (
|
||||
!Object.values(partial.cleanup).some(
|
||||
({ state }) => state === "failed" || state === "unverified",
|
||||
)
|
||||
)
|
||||
const cleanupIncomplete = Object.values(partial.cleanup).some(
|
||||
({ state }) => state === "failed" || state === "unverified",
|
||||
);
|
||||
if (!cleanupIncomplete && partial.execution_failure === null)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["cleanup"],
|
||||
message: "partial observations require incomplete resource cleanup",
|
||||
path: ["execution_failure"],
|
||||
message:
|
||||
"partial observations require incomplete cleanup or an execution failure",
|
||||
});
|
||||
|
||||
if ("observations" in partial) {
|
||||
|
||||
Reference in New Issue
Block a user