Skip to content

Commit 8d0b36b

Browse files
authored
fix(testing-sdk): use a better error message when error data is missing (#373)
*Issue #, if available:* #361 *Description of changes:* Currently, the testing SDK throws a generic `Could not find error result` If the execution times out (or fails) with no error message. This PR improves that by saying `Execution failed with status "TIMED_OUT"` in this case instead. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 984e418 commit 8d0b36b

File tree

2 files changed

+38
-62
lines changed

2 files changed

+38
-62
lines changed

packages/aws-durable-execution-sdk-js-testing/src/test-runner/local/__tests__/result-formatter.test.ts

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -375,23 +375,6 @@ describe("ResultFormatter", () => {
375375
expect(testResult.getResult()).toEqual(complexData);
376376
});
377377

378-
it("should throw Error when error object is not found for failed execution", () => {
379-
const lambdaResponse: TestExecutionResult = {
380-
status: ExecutionStatus.FAILED,
381-
result: JSON.stringify({ error: "" }),
382-
};
383-
384-
const testResult = resultFormatter.formatTestResult(
385-
lambdaResponse,
386-
[],
387-
mockOperationStorage,
388-
);
389-
390-
expect(() => testResult.getResult()).toThrow(
391-
"Could not find error result",
392-
);
393-
});
394-
395378
it("should not clean stack trace if error had no stack trace", () => {
396379
const lambdaResponse: TestExecutionResult = {
397380
status: ExecutionStatus.FAILED,
@@ -411,12 +394,12 @@ describe("ResultFormatter", () => {
411394
thrownError = error as Error;
412395
}
413396
expect(thrownError!.stack).toBeDefined();
414-
expect(thrownError!.stack).toContain("ResultFormatter");
397+
expect(thrownError!.stack).toContain("result-formatter.ts");
415398
});
416399
});
417400

418401
describe("getError behavior", () => {
419-
it("should not return ErrorObject for failed invocation if error object is missing", () => {
402+
it("should return generic error when error object is missing", () => {
420403
const mockError = "Handler execution failed";
421404

422405
const lambdaResponse: TestExecutionResult = {
@@ -430,9 +413,13 @@ describe("ResultFormatter", () => {
430413
mockOperationStorage,
431414
);
432415

433-
expect(() => testResult.getError()).toThrow(
434-
"Could not find error result",
435-
);
416+
const error = testResult.getError();
417+
expect(error).toEqual({
418+
errorMessage: 'Execution failed with status "FAILED"',
419+
errorData: undefined,
420+
errorType: undefined,
421+
stackTrace: undefined,
422+
});
436423
});
437424

438425
it("should throw error when called on successful execution", () => {
@@ -452,40 +439,6 @@ describe("ResultFormatter", () => {
452439
);
453440
});
454441

455-
it("should throw error when parsing fails", () => {
456-
const lambdaResponse: TestExecutionResult = {
457-
status: ExecutionStatus.FAILED,
458-
result: "Raw error message - not JSON",
459-
};
460-
461-
const testResult = resultFormatter.formatTestResult(
462-
lambdaResponse,
463-
[],
464-
mockOperationStorage,
465-
);
466-
467-
expect(() => testResult.getError()).toThrow(
468-
"Could not find error result",
469-
);
470-
});
471-
472-
it("should throw error when error field is not a string", () => {
473-
const lambdaResponse: TestExecutionResult = {
474-
status: ExecutionStatus.FAILED,
475-
result: JSON.stringify({ error: { nested: "object" } }),
476-
};
477-
478-
const testResult = resultFormatter.formatTestResult(
479-
lambdaResponse,
480-
[],
481-
mockOperationStorage,
482-
);
483-
484-
expect(() => testResult.getError()).toThrow(
485-
"Could not find error result",
486-
);
487-
});
488-
489442
it("should return ErrorObject when error object is specified", () => {
490443
const lambdaResponse: TestExecutionResult = {
491444
status: ExecutionStatus.FAILED,
@@ -672,5 +625,27 @@ describe("ResultFormatter", () => {
672625
stackTrace: ["stack line 1", "stack line 2"],
673626
});
674627
});
628+
629+
it("should return timeout error when status is TIMED_OUT and no error data exists", () => {
630+
const lambdaResponse: TestExecutionResult = {
631+
status: ExecutionStatus.TIMED_OUT,
632+
result: JSON.stringify({ someField: "value" }),
633+
// No error property - testing the TIMED_OUT specific case
634+
};
635+
636+
const testResult = resultFormatter.formatTestResult(
637+
lambdaResponse,
638+
[],
639+
mockOperationStorage,
640+
);
641+
642+
const error = testResult.getError();
643+
expect(error).toEqual({
644+
errorMessage: `Execution failed with status "TIMED_OUT"`,
645+
errorData: undefined,
646+
errorType: undefined,
647+
stackTrace: undefined,
648+
});
649+
});
675650
});
676651
});

packages/aws-durable-execution-sdk-js-testing/src/test-runner/local/result-formatter.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ export class ResultFormatter<ResultType> {
5353
if (lambdaResponse.status !== ExecutionStatus.SUCCEEDED) {
5454
const errorFromResult = this.getErrorFromResult(lambdaResponse);
5555

56-
const error = new Error(
57-
errorFromResult.errorMessage?.trim()
58-
? errorFromResult.errorMessage
59-
: "Execution failed",
60-
);
56+
const error = new Error(errorFromResult.errorMessage?.trim());
6157

6258
if (errorFromResult.stackTrace) {
6359
error.stack = errorFromResult.stackTrace.join("\n");
@@ -131,6 +127,11 @@ export class ResultFormatter<ResultType> {
131127
};
132128
}
133129

134-
throw new Error("Could not find error result");
130+
return {
131+
errorMessage: `Execution failed with status "${result.status}"`,
132+
errorData: undefined,
133+
errorType: undefined,
134+
stackTrace: undefined,
135+
};
135136
}
136137
}

0 commit comments

Comments
 (0)