1
+ /* eslint-disable promise/catch-or-return */
2
+
1
3
// ↓ Should be imported first
2
- require ( '@codefresh-io/cf-telemetry/init' ) ;
4
+ const { terminate } = require ( '@codefresh-io/cf-telemetry/init' ) ;
3
5
// ↓ Keep one blank line below to prevent automatic import reordering
4
6
5
7
const { Logger } = require ( '@codefresh-io/cf-telemetry/logs' ) ;
@@ -43,14 +45,14 @@ async function updateMasks(secret) {
43
45
if ( response . statusCode === 201 ) {
44
46
logger . log ( `successfully updated masks with secret: ${ secret . key } ` ) ;
45
47
exitWithError = false ;
46
- process . exit ( exitCodes . success ) ;
48
+ terminate ( ) . finally ( ( ) => process . exit ( exitCodes . success ) ) ;
47
49
} else {
48
50
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 ) ) ;
50
52
}
51
53
} catch ( error ) {
52
54
logger . error ( `could not create mask for secret: ${ secret . key } . Error: ${ error } ` ) ;
53
- process . exit ( exitCodes . error ) ;
55
+ terminate ( ) . finally ( ( ) => process . exit ( exitCodes . error ) ) ;
54
56
}
55
57
}
56
58
@@ -60,7 +62,7 @@ if (require.main === module) {
60
62
// first argument is the secret key second argument is the secret value
61
63
if ( process . argv . length < 4 ) {
62
64
logger . log ( 'not enough arguments, need secret key and secret value' ) ;
63
- process . exit ( exitCodes . missingArguments ) ;
65
+ terminate ( ) . finally ( ( ) => process . exit ( exitCodes . missingArguments ) ) ;
64
66
}
65
67
const key = process . argv [ 2 ] ;
66
68
const value = process . argv [ 3 ] ;
0 commit comments