Skip to content

Commit

Permalink
chore: added error handling for invalid patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Aug 20, 2024
1 parent e0f062d commit d1b05b9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/client/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ErrorClientAuthDenied<T> extends ErrorClient<T> {
exitCode = sysexits.NOPERM;
}

class ErrorClientFileReadFailed<T> extends ErrorClient<T> {
static description = 'Failed to read file or directory';
class ErrorClientFSReadFailed<T> extends ErrorClient<T> {
static description = 'Failed to read from filesystem';
exitCode = sysexits.IOERR;
}

Expand Down Expand Up @@ -50,7 +50,7 @@ export {
ErrorClientAuthMissing,
ErrorClientAuthFormat,
ErrorClientAuthDenied,
ErrorClientFileReadFailed,
ErrorClientFSReadFailed,
ErrorClientService,
ErrorClientServiceRunning,
ErrorClientServiceNotRunning,
Expand Down
4 changes: 2 additions & 2 deletions src/client/handlers/VaultsSecretsGetFileTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
);
Expand Down
7 changes: 3 additions & 4 deletions tests/client/handlers/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1589,19 +1589,18 @@ describe('vaultsSecretsNewDir and vaultsSecretsList', () => {
});
expect(addResponse.success).toBeTruthy();

expect(async () => {
await expect(async () => {
const files = await rpcClient.methods.vaultsSecretsGetFileTree({
nameOrId: vaultsIdEncoded,
pattern: 'doesntExist',
yieldStats: false,
});
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({
Expand Down

0 comments on commit d1b05b9

Please sign in to comment.