Skip to content

Commit

Permalink
Handle insufficient disk space errors (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk authored Nov 20, 2024
1 parent 38ca68e commit 249c0e5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/orange-garlics-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/platform-core': patch
---

Handle insufficient disk space errors
2 changes: 1 addition & 1 deletion packages/platform-core/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export abstract class AmplifyError<T extends string = string> extends Error {
// (undocumented)
readonly details?: string;
// (undocumented)
static fromError: (error: unknown) => AmplifyError<'UnknownFault' | 'CredentialsError' | 'InvalidCommandInputError' | 'DomainNotFoundError' | 'SyntaxError'>;
static fromError: (error: unknown) => AmplifyError<'UnknownFault' | 'CredentialsError' | 'InsufficientDiskSpaceError' | 'InvalidCommandInputError' | 'DomainNotFoundError' | 'SyntaxError'>;
// (undocumented)
static fromStderr: (_stderr: string) => AmplifyError | undefined;
static isAmplifyError: (error: unknown) => error is AmplifyError<string>;
Expand Down
16 changes: 16 additions & 0 deletions packages/platform-core/src/errors/amplify_error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,20 @@ void describe('AmplifyError.fromError', async () => {
`Failed the test for error ${error.message}`
);
});
void it('wraps InsufficientDiskSpaceError in AmplifyUserError', () => {
const insufficientDiskSpaceErrors = [
new Error(
"ENOSPC: no space left on device, open '/some/path/amplify_outputs.json'"
),
new Error('npm ERR! code ENOSPC'),
];
insufficientDiskSpaceErrors.forEach((error) => {
const actual = AmplifyError.fromError(error);
assert.ok(
AmplifyError.isAmplifyError(actual) &&
actual.name === 'InsufficientDiskSpaceError',
`Failed the test for error ${error.message}`
);
});
});
});
21 changes: 21 additions & 0 deletions packages/platform-core/src/errors/amplify_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export abstract class AmplifyError<T extends string = string> extends Error {
): AmplifyError<
| 'UnknownFault'
| 'CredentialsError'
| 'InsufficientDiskSpaceError'
| 'InvalidCommandInputError'
| 'DomainNotFoundError'
| 'SyntaxError'
Expand Down Expand Up @@ -179,6 +180,17 @@ export abstract class AmplifyError<T extends string = string> extends Error {
error
);
}
if (error instanceof Error && isInsufficientDiskSpaceError(error)) {
return new AmplifyUserError(
'InsufficientDiskSpaceError',
{
message: error.message,
resolution:
'There appears to be insufficient space on your system to finish. Clear up some disk space and try again.',
},
error
);
}
return new AmplifyFault(
'UnknownFault',
{
Expand Down Expand Up @@ -220,6 +232,15 @@ const isSyntaxError = (err?: Error): boolean => {
return !!err && err.name === 'SyntaxError';
};

const isInsufficientDiskSpaceError = (err?: Error): boolean => {
return (
!!err &&
['ENOSPC: no space left on device', 'code ENOSPC'].some((message) =>
err.message.includes(message)
)
);
};

/**
* Amplify exception classifications
*/
Expand Down

0 comments on commit 249c0e5

Please sign in to comment.