Skip to content

Commit

Permalink
fix: manually updated type of error
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
aryanjassal committed Oct 15, 2024
1 parent 685199d commit 063e03b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/secrets/CommandMkdir.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import type { ErrorMessage } from 'polykey/dist/client/types';
import CommandPolykey from '../CommandPolykey';
import * as binUtils from '../utils';
import * as binOptions from '../utils/options';
Expand Down Expand Up @@ -26,7 +27,7 @@ class CommandMkdir extends CommandPolykey {
this.addOption(binOptions.recursive);
this.action(async (secretPaths, options) => {
secretPaths = secretPaths.map((path: string) =>
binParsers.parseSecretPathValue(path),
binParsers.parseSecretPath(path),
);
const { default: PolykeyClient } = await import(
'polykey/dist/PolykeyClient'
Expand Down Expand Up @@ -85,9 +86,13 @@ class CommandMkdir extends CommandPolykey {
let hasErrored = false;
for await (const result of response.readable) {
if (result.type === 'error') {
// TS cannot properly evaluate a type this deeply nested, so we use
// the as keyword to help it. Inside this block, the type of data is
// ensured to be 'error'.
const error = result as ErrorMessage;
hasErrored = true;
let message: string = '';
switch (result.code) {
switch (error.code) {
case 'ENOENT':
message = 'No such secret or directory';
break;
Expand All @@ -96,11 +101,11 @@ class CommandMkdir extends CommandPolykey {
break;
default:
throw new ErrorPolykeyCLIUncaughtException(
`Unexpected error code: ${result.code}`,
`Unexpected error code: ${error.code}`,
);
}
process.stderr.write(
`${result.code}: cannot create directory ${result.reason}: ${message}\n`,
`${error.code}: cannot create directory ${error.reason}: ${message}\n`,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function parseSecretPath(secretPath: string): [string, string, string?] {
// If 'vault1', an error is thrown
const [vaultName, secretName, value] = parseSecretPathOptional(secretPath);
if (secretName === undefined) {
console.log("invalid path")
throw new commander.InvalidArgumentError(
`${secretPath} is not of the format <vaultName>:<directoryPath>[=<value>]`,
);
Expand Down

0 comments on commit 063e03b

Please sign in to comment.