File tree Expand file tree Collapse file tree 4 files changed +23
-8
lines changed Expand file tree Collapse file tree 4 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import type { PolykeyWorkerManagerInterface } from '../../workers/types';
1010import path from 'path' ;
1111import childProcess from 'child_process' ;
1212import process from 'process' ;
13+ import * as keysErrors from '../../keys/errors' ;
1314import CommandPolykey from '../CommandPolykey' ;
1415import * as binUtils from '../utils' ;
1516import * 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 ,
Original file line number Diff line number Diff 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+
3439class 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 ,
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments