@@ -157,7 +157,8 @@ class CommandEnv extends CommandPolykey {
157157 if ( nameOrId != null && secretName == null ) {
158158 // Only vault specified
159159 for ( const key of allKeys ) {
160- // TODO: handle secret renames, allKeys key might not be the same in vault
160+ // When exporting secrets from a vault, it is impossible to
161+ // rename the resulting secrets.
161162 await writer . write ( {
162163 nameOrId : nameOrId ,
163164 secretName : key ,
@@ -166,7 +167,8 @@ class CommandEnv extends CommandPolykey {
166167 }
167168 } else {
168169 // Individual secret name specified
169- const name : string = secretNameNew != null ? secretNameNew : secretName ! ;
170+ const name : string =
171+ secretNameNew != null ? secretNameNew : secretName ! ;
170172 if ( allKeys . includes ( name ) ) {
171173 await writer . write ( {
172174 nameOrId : nameOrId ,
@@ -201,21 +203,26 @@ class CommandEnv extends CommandPolykey {
201203 case 'EINVAL' :
202204 // It is expected for the data to be populated with the offending
203205 // vault name if the vault was not found.
204- process . stderr . write (
205- binUtils . outputFormatterError (
206- `Vault "${ value . data ?. nameOrId } " does not exist` ,
207- ) ,
206+ throw new Error (
207+ `TMP Vault "${ value . data ?. nameOrId } " does not exist` ,
208208 ) ;
209- break ;
210209 case 'ENOENT' :
210+ // If we have a default for this key, then don't bother
211+ // reporting the missing key.
212+ if (
213+ unwrappedSchema != null &&
214+ Object . keys ( unwrappedSchema . defaults ) . includes (
215+ value . data ! . secretName ! . toString ( ) ,
216+ )
217+ ) {
218+ break ;
219+ }
220+
211221 // It is expected for the data to be populated with the offending
212222 // secret and vault name if a secret was not found.
213- process . stderr . write (
214- binUtils . outputFormatterError (
215- `Secret "${ value . data ?. secretName } " does not exist in vault "${ value . data ?. nameOrId } "` ,
216- ) ,
223+ throw new Error (
224+ `TMP Secret "${ value . data ?. secretName } " does not exist in vault "${ value . data ?. nameOrId } "` ,
217225 ) ;
218- break ;
219226 default :
220227 utils . never (
221228 `Expected code to be one of EINVAL, ENOENT, received ${ value . code } ` ,
0 commit comments