@@ -7,26 +7,21 @@ import { clearCachedConfig, encryptValue, getMergedConfig, getNcurcPath } from '
77
88export default lazy ( auth ) ;
99
10- function errorExit ( message ) {
11- process . stderr . write ( `${ message } \n` ) ;
12- process . exit ( 1 ) ;
13- }
14-
1510function check ( username , token , format = / ^ [ A - Z a - z 0 - 9 _ ] + $ / ) {
1611 if ( typeof username !== 'string' ) {
17- errorExit ( `username must be a string, received ${ typeof username } ` ) ;
12+ throw new Error ( `username must be a string, received ${ typeof username } ` ) ;
1813 }
1914 if ( ! / ^ [ a - z A - Z 0 - 9 - ] + $ / . test ( username ) ) {
20- errorExit (
15+ throw new Error (
2116 'username may only contain alphanumeric characters or hyphens, ' +
2217 `received ${ username } `
2318 ) ;
2419 }
2520 if ( typeof token !== 'string' ) {
26- errorExit ( `token must be a string, received ${ typeof token } ` ) ;
21+ throw new Error ( `token must be a string, received ${ typeof token } ` ) ;
2722 }
2823 if ( ! format . test ( token ) ) {
29- errorExit ( `token is misformatted: ${ token } ` ) ;
24+ throw new Error ( `token is misformatted: ${ token } ` ) ;
3025 }
3126}
3227
@@ -51,7 +46,7 @@ async function tryCreateGitHubToken(githubAuth) {
5146 noDeviceFlow : true
5247 } ) ;
5348 } catch ( e ) {
54- errorExit ( `Could not get token: ${ e . message } ` ) ;
49+ throw new Error ( `Could not get token: ${ e . message } ` , { cause : e } ) ;
5550 }
5651 return credentials ;
5752}
@@ -93,7 +88,7 @@ async function auth(
9388 get jenkins ( ) {
9489 const { username, jenkins_token } = getMergedConfig ( ) ;
9590 if ( ! username || ! jenkins_token ) {
96- errorExit (
91+ throw new Error (
9792 'Get your Jenkins API token in https://ci.nodejs.org/me/security ' +
9893 'and run the following command to add it to your ncu config: ' +
9994 'ncu-config --global set -x jenkins_token'
0 commit comments