Skip to content

Commit a0bd3ec

Browse files
tegefaulkesCMCDragonkai
authored andcommitted
fix: simplified invalid password output and error output
[ci skip]
1 parent df09bbe commit a0bd3ec

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/bin/agent/CommandStart.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { PolykeyWorkerManagerInterface } from '../../workers/types';
1010
import path from 'path';
1111
import childProcess from 'child_process';
1212
import process from 'process';
13+
import * as keysErrors from '../../keys/errors';
1314
import CommandPolykey from '../CommandPolykey';
1415
import * as binUtils from '../utils';
1516
import * as binOptions from '../utils/options';
@@ -218,11 +219,18 @@ class CommandStart extends CommandPolykey {
218219
await workerManager?.destroy();
219220
await pkAgent?.stop();
220221
});
221-
pkAgent = await PolykeyAgent.createPolykeyAgent({
222-
fs: this.fs,
223-
logger: this.logger.getChild(PolykeyAgent.name),
224-
...agentConfig,
225-
});
222+
try {
223+
pkAgent = await PolykeyAgent.createPolykeyAgent({
224+
fs: this.fs,
225+
logger: this.logger.getChild(PolykeyAgent.name),
226+
...agentConfig,
227+
});
228+
} catch (e) {
229+
if (e instanceof keysErrors.ErrorKeyPairParse) {
230+
throw new binErrors.ErrorCLIPasswordWrong();
231+
}
232+
throw e;
233+
}
226234
if (options.workers !== 0) {
227235
workerManager = await workersUtils.createWorkerManager({
228236
cores: options.workers,

src/bin/errors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class ErrorCLIClientOptions<T> extends ErrorCLI<T> {
3131
exitCode = sysexits.USAGE;
3232
}
3333

34+
class ErrorCLIPasswordWrong<T> extends ErrorCLI<T> {
35+
static description = 'Wrong password, please try again';
36+
exitCode = sysexits.USAGE;
37+
}
38+
3439
class ErrorCLIPasswordMissing<T> extends ErrorCLI<T> {
3540
static description =
3641
'Password is necessary, provide it via --password-file, PK_PASSWORD or when prompted';
@@ -90,6 +95,7 @@ export {
9095
ErrorCLI,
9196
ErrorCLINodePath,
9297
ErrorCLIClientOptions,
98+
ErrorCLIPasswordWrong,
9399
ErrorCLIPasswordMissing,
94100
ErrorCLIPasswordFileRead,
95101
ErrorCLIRecoveryCodeFileRead,

src/bin/utils/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ function outputFormatter(msg: OutputObject): string {
127127
output += ` - ${currError.message}`;
128128
}
129129
output += '\n';
130-
output += `${indent}exitCode\t${currError.exitCode}\n`;
131-
output += `${indent}timestamp\t${currError.timestamp}\n`;
130+
// Disabled to streamline output
131+
// output += `${indent}exitCode\t${currError.exitCode}\n`;
132+
// output += `${indent}timestamp\t${currError.timestamp}\n`;
132133
if (currError.data && !utils.isEmptyObject(currError.data)) {
133134
output += `${indent}data\t${JSON.stringify(currError.data)}\n`;
134135
}

tests/bin/secrets/secrets.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('CLI secrets', () => {
134134
env: {},
135135
cwd: dataDir,
136136
});
137-
expect(result.stdout).toBe('MySecret: this is the secret\n')
137+
expect(result.stdout).toBe('MySecret: this is the secret\n');
138138
expect(result.exitCode).toBe(0);
139139
},
140140
);

0 commit comments

Comments
 (0)