Skip to content

Commit 063e03b

Browse files
committed
fix: manually updated type of error
[ci skip]
1 parent 685199d commit 063e03b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/secrets/CommandMkdir.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type PolykeyClient from 'polykey/dist/PolykeyClient';
2+
import type { ErrorMessage } from 'polykey/dist/client/types';
23
import CommandPolykey from '../CommandPolykey';
34
import * as binUtils from '../utils';
45
import * as binOptions from '../utils/options';
@@ -26,7 +27,7 @@ class CommandMkdir extends CommandPolykey {
2627
this.addOption(binOptions.recursive);
2728
this.action(async (secretPaths, options) => {
2829
secretPaths = secretPaths.map((path: string) =>
29-
binParsers.parseSecretPathValue(path),
30+
binParsers.parseSecretPath(path),
3031
);
3132
const { default: PolykeyClient } = await import(
3233
'polykey/dist/PolykeyClient'
@@ -85,9 +86,13 @@ class CommandMkdir extends CommandPolykey {
8586
let hasErrored = false;
8687
for await (const result of response.readable) {
8788
if (result.type === 'error') {
89+
// TS cannot properly evaluate a type this deeply nested, so we use
90+
// the as keyword to help it. Inside this block, the type of data is
91+
// ensured to be 'error'.
92+
const error = result as ErrorMessage;
8893
hasErrored = true;
8994
let message: string = '';
90-
switch (result.code) {
95+
switch (error.code) {
9196
case 'ENOENT':
9297
message = 'No such secret or directory';
9398
break;
@@ -96,11 +101,11 @@ class CommandMkdir extends CommandPolykey {
96101
break;
97102
default:
98103
throw new ErrorPolykeyCLIUncaughtException(
99-
`Unexpected error code: ${result.code}`,
104+
`Unexpected error code: ${error.code}`,
100105
);
101106
}
102107
process.stderr.write(
103-
`${result.code}: cannot create directory ${result.reason}: ${message}\n`,
108+
`${error.code}: cannot create directory ${error.reason}: ${message}\n`,
104109
);
105110
}
106111
}

src/utils/parsers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ function parseSecretPath(secretPath: string): [string, string, string?] {
9494
// If 'vault1', an error is thrown
9595
const [vaultName, secretName, value] = parseSecretPathOptional(secretPath);
9696
if (secretName === undefined) {
97+
console.log("invalid path")
9798
throw new commander.InvalidArgumentError(
9899
`${secretPath} is not of the format <vaultName>:<directoryPath>[=<value>]`,
99100
);

0 commit comments

Comments
 (0)