From d1b05b9575da4376bcd9ca75d59d0b9bf066d939 Mon Sep 17 00:00:00 2001 From: Aryan Jassal Date: Tue, 20 Aug 2024 16:21:41 +1000 Subject: [PATCH] chore: added error handling for invalid patterns --- src/client/errors.ts | 6 +++--- src/client/handlers/VaultsSecretsGetFileTree.ts | 4 ++-- tests/client/handlers/vaults.test.ts | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/client/errors.ts b/src/client/errors.ts index 12a8093bd..edf76e6d0 100644 --- a/src/client/errors.ts +++ b/src/client/errors.ts @@ -18,8 +18,8 @@ class ErrorClientAuthDenied extends ErrorClient { exitCode = sysexits.NOPERM; } -class ErrorClientFileReadFailed extends ErrorClient { - static description = 'Failed to read file or directory'; +class ErrorClientFSReadFailed extends ErrorClient { + static description = 'Failed to read from filesystem'; exitCode = sysexits.IOERR; } @@ -50,7 +50,7 @@ export { ErrorClientAuthMissing, ErrorClientAuthFormat, ErrorClientAuthDenied, - ErrorClientFileReadFailed, + ErrorClientFSReadFailed, ErrorClientService, ErrorClientServiceRunning, ErrorClientServiceNotRunning, diff --git a/src/client/handlers/VaultsSecretsGetFileTree.ts b/src/client/handlers/VaultsSecretsGetFileTree.ts index 9492f65ac..ddbc8918d 100644 --- a/src/client/handlers/VaultsSecretsGetFileTree.ts +++ b/src/client/handlers/VaultsSecretsGetFileTree.ts @@ -54,14 +54,14 @@ class VaultsSecretsGetFileTree extends ServerHandler< stat: input.yieldStats ? generateStats(stat) : undefined, }; } catch (e) { - throw new clientErrors.ErrorClientFileReadFailed( + throw new clientErrors.ErrorClientFSReadFailed( `Failed to read file: ${file}`, { cause: e }, ); } } } catch (e) { - throw new clientErrors.ErrorClientFileReadFailed( + throw new clientErrors.ErrorClientFSReadFailed( `Failed to read directory: ${input.pattern}`, { cause: e }, ); diff --git a/tests/client/handlers/vaults.test.ts b/tests/client/handlers/vaults.test.ts index 17e44dd50..593c84e96 100644 --- a/tests/client/handlers/vaults.test.ts +++ b/tests/client/handlers/vaults.test.ts @@ -1589,7 +1589,7 @@ describe('vaultsSecretsNewDir and vaultsSecretsList', () => { }); expect(addResponse.success).toBeTruthy(); - expect(async () => { + await expect(async () => { const files = await rpcClient.methods.vaultsSecretsGetFileTree({ nameOrId: vaultsIdEncoded, pattern: 'doesntExist', @@ -1597,11 +1597,10 @@ describe('vaultsSecretsNewDir and vaultsSecretsList', () => { }); try { for await (const _ of files); // Consume values - } - catch (e) { + } catch (e) { throw e.cause; } - }).rejects.toThrow(clientErrors.ErrorClientFileReadFailed); + }).rejects.toThrow(clientErrors.ErrorClientFSReadFailed); // List secrets with names of directories const secrets = await rpcClient.methods.vaultsSecretsGetFileTree({