Skip to content

Commit

Permalink
chore: wrap out of memory errors (#2365)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amplifiyer authored Dec 23, 2024
1 parent b574bce commit abff5a0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-schools-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/platform-core': patch
---

add InsufficientMemorySpaceError wrapping
11 changes: 11 additions & 0 deletions packages/platform-core/src/errors/amplify_error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,15 @@ void describe('AmplifyError.fromError', async () => {
assert.deepStrictEqual(error, actual);
assert.strictEqual(actual.resolution, error.resolution);
});
void it('wraps InsufficientMemorySpaceError in AmplifyUserError', () => {
const error = new Error(
'FATAL ERROR: Zone Allocation failed - process out of memory.'
);
const actual = AmplifyError.fromError(error);
assert.ok(
AmplifyError.isAmplifyError(actual) &&
actual.name === 'InsufficientMemorySpaceError',
`Failed the test for error ${error.message}`
);
});
});
15 changes: 15 additions & 0 deletions packages/platform-core/src/errors/amplify_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ export abstract class AmplifyError<T extends string = string> extends Error {
error
);
}
if (error instanceof Error && isOutOfMemoryError(error)) {
return new AmplifyUserError(
'InsufficientMemorySpaceError',
{
message: error.message,
resolution:
'There appears to be insufficient memory on your system to finish. Close other applications or restart your system and try again.',
},
error
);
}
return new AmplifyFault(
'UnknownFault',
{
Expand Down Expand Up @@ -245,6 +256,10 @@ const isInsufficientDiskSpaceError = (err?: Error): boolean => {
);
};

const isOutOfMemoryError = (err?: Error): boolean => {
return !!err && err.message.includes('process out of memory');
};

/**
* Amplify exception classifications
*/
Expand Down

0 comments on commit abff5a0

Please sign in to comment.