Skip to content

Commit

Permalink
improve wording
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed May 15, 2023
1 parent 537da2c commit 04ac08c
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 71 deletions.
16 changes: 2 additions & 14 deletions code/lib/cli/src/js-package-manager/NPMProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ describe('NPM Proxy', () => {
`;

expect(npmProxy.parseErrorFromLogs(NPM_ERROR_SAMPLE)).toEqual(
'ERESOLVE: Dependency resolution error.'
'NPM error ERESOLVE - Dependency resolution error.'
);
});

Expand All @@ -479,19 +479,7 @@ describe('NPM Proxy', () => {
npm ERR! react@"30" from the root project
`;

expect(npmProxy.parseErrorFromLogs(NPM_ERROR_SAMPLE)).toEqual(`Unknown NPM error`);
});

it('should show unknown npm error with code if it at least matches the pattern', () => {
const NPM_ERROR_SAMPLE = `
npm ERR! code ESOMETHING
npm ERR! ESOMETHING something something
npm ERR!
`;

expect(npmProxy.parseErrorFromLogs(NPM_ERROR_SAMPLE)).toEqual(
`Unknown NPM error: ESOMETHING`
);
expect(npmProxy.parseErrorFromLogs(NPM_ERROR_SAMPLE)).toEqual(`NPM error`);
});
});
});
15 changes: 10 additions & 5 deletions code/lib/cli/src/js-package-manager/NPMProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,21 @@ export class NPMProxy extends JsPackageManager {
}

public parseErrorFromLogs(logs: string): string {
let finalMessage = 'NPM error';
const match = logs.match(NPM_ERROR_REGEX);
let errorCode;

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

const errorMessage = NPM_ERROR_CODES[errorCode];
if (errorCode && errorMessage) {
return `${errorCode}: ${errorMessage}`.trim();
if (errorMessage) {
finalMessage = `${finalMessage} - ${errorMessage}`;
}
}

return `Unknown NPM error${errorCode ? `: ${errorCode}` : ''}`;
return finalMessage.trim();
}
}
16 changes: 2 additions & 14 deletions code/lib/cli/src/js-package-manager/PNPMProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ describe('NPM Proxy', () => {
`;

expect(pnpmProxy.parseErrorFromLogs(PNPM_ERROR_SAMPLE)).toEqual(
'ERR_PNPM_NO_MATCHING_VERSION: No matching version found for react@29.2.0'
'PNPM error ERR_PNPM_NO_MATCHING_VERSION No matching version found for react@29.2.0'
);
});

Expand All @@ -398,19 +398,7 @@ describe('NPM Proxy', () => {
The latest release of react is "18.2.0".
`;

expect(pnpmProxy.parseErrorFromLogs(PNPM_ERROR_SAMPLE)).toEqual(`Unknown PNPM error`);
});

it('should show unknown pnpm error with code if it at least matches the pattern', () => {
const PNPM_ERROR_SAMPLE = `
ERR_PNPM_SOMETHING No matching version found for react@29.2.0
This error happened while installing a direct dependency of /Users/yannbraga/open-source/sandboxes/react-vite/default-js/before-storybook
`;

expect(pnpmProxy.parseErrorFromLogs(PNPM_ERROR_SAMPLE)).toEqual(
`Unknown PNPM error: ERR_PNPM_SOMETHING`
);
expect(pnpmProxy.parseErrorFromLogs(PNPM_ERROR_SAMPLE)).toEqual(`PNPM error`);
});
});
});
31 changes: 6 additions & 25 deletions code/lib/cli/src/js-package-manager/PNPMProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,6 @@ type PnpmListItem = {
export type PnpmListOutput = PnpmListItem[];

const PNPM_ERROR_REGEX = /(ELIFECYCLE|ERR_PNPM_[A-Z_]+)\s+(.*)/i;
const PNPM_ERROR_CODES = {
ELIFECYCLE: 'Lifecycle error',
ERR_PNPM_BAD_TARBALL_SIZE: 'Bad tarball size error',
ERR_PNPM_DEDUPE_CHECK_ISSUES: 'Dedupe check issues error',
ERR_PNPM_FETCH_401: 'Fetch 401 error',
ERR_PNPM_FETCH_403: 'Fetch 403 error',
ERR_PNPM_LOCKFILE_BREAKING_CHANGE: 'Lockfile breaking change error',
ERR_PNPM_MODIFIED_DEPENDENCY: 'Modified dependency error',
ERR_PNPM_MODULES_BREAKING_CHANGE: 'Modules breaking change error',
ERR_PNPM_NO_MATCHING_VERSION: 'No matching version error',
ERR_PNPM_PEER_DEP_ISSUES: 'Peer dependency issues error',
ERR_PNPM_RECURSIVE_FAIL: 'Recursive command failed error',
ERR_PNPM_RECURSIVE_RUN_NO_SCRIPT: 'Recursive run no script error',
ERR_PNPM_STORE_BREAKING_CHANGE: 'Store breaking change error',
ERR_PNPM_UNEXPECTED_STORE: 'Unexpected store error',
ERR_PNPM_UNEXPECTED_VIRTUAL_STORE: 'Unexpected virtual store error',
ERR_PNPM_UNSUPPORTED_ENGINE: 'Unsupported engine error',
};

export class PNPMProxy extends JsPackageManager {
readonly type = 'pnpm';
Expand Down Expand Up @@ -255,16 +237,15 @@ export class PNPMProxy extends JsPackageManager {
}

public parseErrorFromLogs(logs: string): string {
let finalMessage = 'PNPM error';
const match = logs.match(PNPM_ERROR_REGEX);
let errorCode;
if (match) {
errorCode = match[1] as keyof typeof PNPM_ERROR_CODES;
const errorMessage = match[2];
const errorType = PNPM_ERROR_CODES[errorCode];
if (errorType && errorMessage) {
return `${errorCode}: ${errorMessage}`.trim();
const [errorCode] = match;
if (errorCode) {
finalMessage = `${finalMessage} ${errorCode}`;
}
}
return `Unknown PNPM error${errorCode ? `: ${errorCode}` : ''}`;

return finalMessage.trim();
}
}
4 changes: 2 additions & 2 deletions code/lib/cli/src/js-package-manager/Yarn1Proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ describe('Yarn 1 Proxy', () => {
`;

expect(yarn1Proxy.parseErrorFromLogs(YARN1_ERROR_SAMPLE)).toEqual(
`YARN1: Couldn't find any versions for "react" that matches "28.2.0"`
`YARN1 error: Couldn't find any versions for "react" that matches "28.2.0"`
);
});

Expand All @@ -298,7 +298,7 @@ describe('Yarn 1 Proxy', () => {
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
`;

expect(yarn1Proxy.parseErrorFromLogs(YARN1_ERROR_SAMPLE)).toEqual(`Unknown Yarn1 error`);
expect(yarn1Proxy.parseErrorFromLogs(YARN1_ERROR_SAMPLE)).toEqual(`YARN1 error`);
});
});
});
8 changes: 5 additions & 3 deletions code/lib/cli/src/js-package-manager/Yarn1Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,16 @@ export class Yarn1Proxy extends JsPackageManager {
}

public parseErrorFromLogs(logs: string): string {
let finalMessage = 'YARN1 error';
const match = logs.match(YARN1_ERROR_REGEX);

if (match) {
const errorMessage = match[0].replace(/^error\s(.*)$/, '$1');
const errorMessage = match[0]?.replace(/^error\s(.*)$/, '$1');
if (errorMessage) {
return `YARN1: ${errorMessage}`.trim();
finalMessage = `${finalMessage}: ${errorMessage}`;
}
}

return `Unknown Yarn1 error`;
return finalMessage.trim();
}
}
4 changes: 2 additions & 2 deletions code/lib/cli/src/js-package-manager/Yarn2Proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ describe('Yarn 2 Proxy', () => {
`;

expect(yarn2Proxy.parseErrorFromLogs(YARN2_ERROR_SAMPLE)).toEqual(
'YN0001 - EXCEPTION: react@npm:28.2.0: No candidates found'
'YARN2 error YN0001 - EXCEPTION: react@npm:28.2.0: No candidates found'
);
});

Expand All @@ -302,7 +302,7 @@ describe('Yarn 2 Proxy', () => {
➤ YN0061: @npmcli/move-file@npm:2.0.1 is deprecated: This functionality has been moved to @npmcli/fs
`;

expect(yarn2Proxy.parseErrorFromLogs(YARN2_ERROR_SAMPLE)).toEqual(`Unknown Yarn2 error`);
expect(yarn2Proxy.parseErrorFromLogs(YARN2_ERROR_SAMPLE)).toEqual(`YARN2 error`);
});
});
});
20 changes: 14 additions & 6 deletions code/lib/cli/src/js-package-manager/Yarn2Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,26 @@ export class Yarn2Proxy extends JsPackageManager {
}

public parseErrorFromLogs(logs: string): string {
let finalMessage = 'YARN2 error';
const match = logs.match(YARN2_ERROR_REGEX);
let errorCode;

if (match) {
errorCode = match[1] as keyof typeof YARN2_ERROR_CODES;
const errorMessage = match[2];
const errorCode = match[1] as keyof typeof YARN2_ERROR_CODES;
if (errorCode) {
finalMessage = `${finalMessage} ${errorCode}`;
}

const errorType = YARN2_ERROR_CODES[errorCode];
if (errorCode && errorMessage) {
return `${errorCode} - ${errorType}: ${errorMessage}`.trim();
if (errorType) {
finalMessage = `${finalMessage} - ${errorType}`;
}

const errorMessage = match[2];
if (errorMessage) {
finalMessage = `${finalMessage}: ${errorMessage}`;
}
}

return `Unknown Yarn2 error${errorCode ? `: ${errorCode}` : ''}`;
return finalMessage.trim();
}
}

0 comments on commit 04ac08c

Please sign in to comment.