@@ -85,24 +85,29 @@ class CommandEdit extends CommandPolykey {
8585 await fd . write ( Buffer . from ( chunk . secretContent , 'binary' ) ) ;
8686 break ;
8787 case 'ErrorMessage' :
88- // We expect the ENOENT error, so do nothing if we get that
89- if ( chunk . code === 'EISDIR' ) {
90- // First, write the inline error to standard error like other
91- // secrets commands do.
92- process . stderr . write (
93- `edit: ${ secretPath } : No such file or directory\n` ,
94- ) ;
95- // Then, throw an error to get the non-zero exit code. As this
96- // command is Polykey-specific, the code doesn't really matter
97- // that much.
98- throw new errors . ErrorPolykeyCLIEditSecret (
99- 'The specified secret cannot be edited' ,
100- ) ;
101- } else {
102- throw new errors . ErrorPolykeyCLIEditSecret (
103- `Unexpected error value returned: ${ chunk . code } (${ chunk . data } )` ,
104- ) ;
88+ switch ( chunk . code ) {
89+ case 'ENOENT' :
90+ // Do nothing if we get ENOENT. We need a case to avoid
91+ // this value hitting the default case.
92+ break ;
93+ case 'EISDIR' :
94+ // First, write the inline error to standard error like
95+ // other secrets commands do.
96+ process . stderr . write (
97+ `edit: ${ secretPath } : No such file or directory\n` ,
98+ ) ;
99+ // Then, throw an error to get the non-zero exit code.
100+ // As this command is Polykey-specific, the code doesn't
101+ // really matter that much.
102+ throw new errors . ErrorPolykeyCLIEditSecret (
103+ 'The specified secret cannot be edited' ,
104+ ) ;
105+ default :
106+ throw new errors . ErrorPolykeyCLIEditSecret (
107+ `Unexpected error value returned: ${ chunk . code } ` ,
108+ ) ;
105109 }
110+ break ;
106111 default :
107112 never (
108113 `Expected "SuccessMessage" or "ContentMessage", got ${ type } ` ,
0 commit comments