1+ /* eslint-disable promise/catch-or-return */
2+
13// ↓ Should be imported first
2- require ( '@codefresh-io/cf-telemetry/init' ) ;
4+ const { terminate } = require ( '@codefresh-io/cf-telemetry/init' ) ;
35// ↓ Keep one blank line below to prevent automatic import reordering
46
57const { Logger } = require ( '@codefresh-io/cf-telemetry/logs' ) ;
@@ -43,14 +45,14 @@ async function updateMasks(secret) {
4345 if ( response . statusCode === 201 ) {
4446 logger . log ( `successfully updated masks with secret: ${ secret . key } ` ) ;
4547 exitWithError = false ;
46- process . exit ( exitCodes . success ) ;
48+ terminate ( ) . finally ( ( ) => process . exit ( exitCodes . success ) ) ;
4749 } else {
4850 logger . error ( `could not create mask for secret: ${ secret . key } . Server responded with: ${ response . statusCode } \n\n${ response . body } ` ) ;
49- process . exit ( exitCodes . error ) ;
51+ terminate ( ) . finally ( ( ) => process . exit ( exitCodes . error ) ) ;
5052 }
5153 } catch ( error ) {
5254 logger . error ( `could not create mask for secret: ${ secret . key } . Error: ${ error } ` ) ;
53- process . exit ( exitCodes . error ) ;
55+ terminate ( ) . finally ( ( ) => process . exit ( exitCodes . error ) ) ;
5456 }
5557}
5658
@@ -60,7 +62,7 @@ if (require.main === module) {
6062 // first argument is the secret key second argument is the secret value
6163 if ( process . argv . length < 4 ) {
6264 logger . log ( 'not enough arguments, need secret key and secret value' ) ;
63- process . exit ( exitCodes . missingArguments ) ;
65+ terminate ( ) . finally ( ( ) => process . exit ( exitCodes . missingArguments ) ) ;
6466 }
6567 const key = process . argv [ 2 ] ;
6668 const value = process . argv [ 3 ] ;
0 commit comments