From ea2950ef8622fe0c5e70368a9a7eecadf8039d91 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 22 Mar 2026 10:19:14 +0100 Subject: [PATCH 1/3] fix(*): throw `Error` objects to help with debugging --- lib/auth.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/auth.js b/lib/auth.js index 79275843..6e6fb3ef 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -7,26 +7,21 @@ import { clearCachedConfig, encryptValue, getMergedConfig, getNcurcPath } from ' export default lazy(auth); -function errorExit(message) { - process.stderr.write(`${message}\n`); - process.exit(1); -} - function check(username, token, format = /^[A-Za-z0-9_]+$/) { if (typeof username !== 'string') { - errorExit(`username must be a string, received ${typeof username}`); + throw new Error(`username must be a string, received ${typeof username}`); } if (!/^[a-zA-Z0-9-]+$/.test(username)) { - errorExit( + throw new Error( 'username may only contain alphanumeric characters or hyphens, ' + `received ${username}` ); } if (typeof token !== 'string') { - errorExit(`token must be a string, received ${typeof token}`); + throw new Error(`token must be a string, received ${typeof token}`); } if (!format.test(token)) { - errorExit(`token is misformatted: ${token}`); + throw new Error(`token is misformatted: ${token}`); } } @@ -51,7 +46,7 @@ async function tryCreateGitHubToken(githubAuth) { noDeviceFlow: true }); } catch (e) { - errorExit(`Could not get token: ${e.message}`); + throw new Error(`Could not get token: ${e.message}`, { cause: e }); } return credentials; } @@ -93,7 +88,7 @@ async function auth( get jenkins() { const { username, jenkins_token } = getMergedConfig(); if (!username || !jenkins_token) { - errorExit( + throw new Error( 'Get your Jenkins API token in https://ci.nodejs.org/me/security ' + 'and run the following command to add it to your ncu config: ' + 'ncu-config --global set -x jenkins_token' From a6552f1b93fb465d9ad0a7fae8457bcada6f9087 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 24 Mar 2026 12:49:27 +0100 Subject: [PATCH 2/3] fixup! fix(*): throw `Error` objects to help with debugging --- test/unit/auth.test.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/unit/auth.test.js b/test/unit/auth.test.js index db5119ef..96f47206 100644 --- a/test/unit/auth.test.js +++ b/test/unit/auth.test.js @@ -62,7 +62,7 @@ describe('auth', async function() { await runAuthScript( {}, [FIRST_TIME_MSG], - 'Could not get token: Bad credentials\n', 'run-auth-error' + /Could not get token: Bad credentials\n/, 'run-auth-error' ); }); @@ -70,7 +70,7 @@ describe('auth', async function() { await runAuthScript( { HOME: { username: {}, token: '0123456789abcdef' } }, [], - 'username must be a string, received object\n' + /username must be a string, received object\n/ ); }); @@ -78,7 +78,7 @@ describe('auth', async function() { await runAuthScript( { HOME: { username: 'nyancat', token: 42 } }, [], - 'token must be a string, received number\n' + /token must be a string, received number\n/ ); }); @@ -86,8 +86,7 @@ describe('auth', async function() { await runAuthScript( { HOME: { username: ' ^^^ ', token: '0123456789abcdef' } }, [], - 'username may only contain alphanumeric characters or hyphens, ' + - 'received ^^^ \n' + /username may only contain alphanumeric characters or hyphens, received \^\^\^ \n/ ); }); @@ -95,7 +94,7 @@ describe('auth', async function() { await runAuthScript( { HOME: { username: 'nyancat', token: '@fhqwhgads' } }, [], - 'token is misformatted: @fhqwhgads\n' + /token is misformatted: @fhqwhgads\n/ ); }); From b6bdada5a2b3286480a91a393b1c80dbaf3f5b37 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 24 Mar 2026 12:51:43 +0100 Subject: [PATCH 3/3] fixup! fix(*): throw `Error` objects to help with debugging --- test/unit/auth.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/auth.test.js b/test/unit/auth.test.js index 96f47206..653f62fb 100644 --- a/test/unit/auth.test.js +++ b/test/unit/auth.test.js @@ -86,7 +86,7 @@ describe('auth', async function() { await runAuthScript( { HOME: { username: ' ^^^ ', token: '0123456789abcdef' } }, [], - /username may only contain alphanumeric characters or hyphens, received \^\^\^ \n/ + /username may only contain alphanumeric characters or hyphens, received {2}\^\^\^ \n/ ); });