Skip to content

Commit 6f34a77

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

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-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
}

0 commit comments

Comments
 (0)