Skip to content

Commit

Permalink
test: fix failure
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Jan 30, 2025
1 parent dd3bea9 commit 3b14472
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/secrets/CommandEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,29 @@ class CommandEdit extends CommandPolykey {
await fd.write(Buffer.from(chunk.secretContent, 'binary'));
break;
case 'ErrorMessage':
// We expect the ENOENT error, so do nothing if we get that
if (chunk.code === 'EISDIR') {
// First, write the inline error to standard error like other
// secrets commands do.
process.stderr.write(
`edit: ${secretPath}: No such file or directory\n`,
);
// Then, throw an error to get the non-zero exit code. As this
// command is Polykey-specific, the code doesn't really matter
// that much.
throw new errors.ErrorPolykeyCLIEditSecret(
'The specified secret cannot be edited',
);
} else {
throw new errors.ErrorPolykeyCLIEditSecret(
`Unexpected error value returned: ${chunk.code} (${chunk.data})`,
);
switch (chunk.code) {
case 'ENOENT':
// Do nothing if we get ENOENT. We need a case to avoid
// this value hitting the default case.
break;
case 'EISDIR':
// First, write the inline error to standard error like
// other secrets commands do.
process.stderr.write(
`edit: ${secretPath}: No such file or directory\n`,
);
// Then, throw an error to get the non-zero exit code.
// As this command is Polykey-specific, the code doesn't
// really matter that much.
throw new errors.ErrorPolykeyCLIEditSecret(
'The specified secret cannot be edited',
);
default:
throw new errors.ErrorPolykeyCLIEditSecret(
`Unexpected error value returned: ${chunk.code}`,
);
}
break;
default:
never(
`Expected "SuccessMessage" or "ContentMessage", got ${type}`,
Expand Down

0 comments on commit 3b14472

Please sign in to comment.