Skip to content

Commit

Permalink
Write a better error message when key not found
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjohansson committed Jan 27, 2021
1 parent 5e5c06a commit cbd20bc
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 3 deletions.
Binary file added .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/vault-action.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions integrationTests/basic/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ describe('integration', () => {
.mockReturnValueOnce(secrets);
}

it('prints a nice error message when secret not found', async () => {
mockInput(`secret/data/test secret ;
secret/data/test secret | NAMED_SECRET ;
secret/data/notFound kehe | NO_SIR ;`);

expect(exportSecrets()).rejects.toEqual(Error(`Unable to retrieve result for "secret/data/notFound". Double check your Key.`));
})

it('get simple secret', async () => {
mockInput('secret/data/test secret');

Expand Down
14 changes: 11 additions & 3 deletions src/secrets.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ async function getSecrets(secretRequests, client) {
body = responseCache.get(requestPath);
cachedResponse = true;
} else {
const result = await client.get(requestPath);
body = result.body;
responseCache.set(requestPath, body);
try {
const result = await client.get(requestPath);
body = result.body;
responseCache.set(requestPath, body);
} catch (error) {
const {response} = error;
if (response.statusCode === 404) {
throw Error(`Unable to retrieve result for "${path}". Double check your Key.`)
}
throw error
}
}
if (!selector.match(/.*[\.].*/)) {
selector = '"' + selector + '"'
Expand Down

0 comments on commit cbd20bc

Please sign in to comment.