Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Refactor NPMProxy error parsing logic #29459

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion code/core/src/common/js-package-manager/NPMProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ describe('NPM Proxy', () => {

describe('parseErrors', () => {
it('should parse npm errors', () => {
const NPM_RESOLVE_ERROR_SAMPLE = `
const NPM_LEGACY_RESOLVE_ERROR_SAMPLE = `
npm ERR!
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
Expand All @@ -439,6 +439,17 @@ describe('NPM Proxy', () => {
npm ERR! react@"30" from the root project
`;

const NPM_RESOLVE_ERROR_SAMPLE = `
npm error
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: before-storybook@1.0.0
npm error Found: react@undefined
npm error node_modules/react
npm error react@"30" from the root project
`;

const NPM_TIMEOUT_ERROR_SAMPLE = `
npm notice
npm notice New major version of npm available! 8.5.0 -> 9.6.7
Expand All @@ -451,6 +462,9 @@ describe('NPM Proxy', () => {
npm ERR! network This is a problem related to network connectivity.
`;

expect(npmProxy.parseErrorFromLogs(NPM_LEGACY_RESOLVE_ERROR_SAMPLE)).toEqual(
'NPM error ERESOLVE - Dependency resolution error.'
);
expect(npmProxy.parseErrorFromLogs(NPM_RESOLVE_ERROR_SAMPLE)).toEqual(
'NPM error ERESOLVE - Dependency resolution error.'
);
Expand Down
4 changes: 2 additions & 2 deletions code/core/src/common/js-package-manager/NPMProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type NpmDependencies = {
export type NpmListOutput = {
dependencies: NpmDependencies;
};
const NPM_ERROR_REGEX = /npm (ERR!|error) (code|errno) (\w+)/i;

const NPM_ERROR_REGEX = /npm ERR! code (\w+)/;
const NPM_ERROR_CODES = {
E401: 'Authentication failed or is required.',
E403: 'Access to the resource is forbidden.',
Expand Down Expand Up @@ -320,7 +320,7 @@ export class NPMProxy extends JsPackageManager {
const match = logs.match(NPM_ERROR_REGEX);

if (match) {
const errorCode = match[1] as keyof typeof NPM_ERROR_CODES;
const errorCode = match[3] as keyof typeof NPM_ERROR_CODES;
if (errorCode) {
finalMessage = `${finalMessage} ${errorCode}`;
}
Expand Down
Loading