Repository navigation
Conversation
…or parser Modern Yarn formats error detail fields such as `Response Code` with ANSI color sequences and OSC 8 hyperlinks before passing them to `StreamReport`, which serializes the formatted strings verbatim into its JSON line output. When colors are enabled, such as by default on GitHub Actions even over non-TTY pipes or via `FORCE_COLOR` and `.yarnrc.yml` settings, escape codes appear around both the `Response Code` label and status number. As a result, `parseYarnModernError` failed to match the HTTP status code, fell back to the generic `YN0035` code instead of `E404` for missing packages, and leaked raw control sequences into the parsed summary and detail text. Strip VT control characters from modern Yarn error messages prior to matching an anchored `Response Code` line, and ignore 2xx status codes for consistency with the Yarn Classic parser. In addition, split multi-line error payloads such as `YN0001` exception stack traces so `summary` only retains the first line while remaining lines move into `detail`, fall back to `UNKNOWN_ERROR` when `displayName` is an empty string (when `enableMessageNames` is disabled), and return `null` directly when no JSON error lines are present instead of delegating to `parseNpmLikeError` on every successful command output.
There was a problem hiding this comment.
Code Review
This pull request refactors the modern Yarn error parser to strip ANSI color codes and OSC 8 hyperlinks from error lines, improves HTTP status code extraction, and refines how error summaries and details are split. It also adds comprehensive unit tests to verify these changes. The review feedback suggests a robust fallback for the error summary to prevent it from being empty when the error data contains only whitespace.
| const [summary = '', ...firstDetailLines] = first.data | ||
| .split('\n') | ||
| .map((line) => line.trim()) | ||
| .filter(Boolean); |
There was a problem hiding this comment.
If first.data is empty or contains only whitespace, the destructured summary will default to an empty string (''). To ensure a robust fallback and prevent empty error summaries, we can default summary to first.code (e.g., 'YN0035' or 'UNKNOWN_ERROR'), which is guaranteed to be a non-empty string.
const [summary = first.code, ...firstDetailLines] = first.data\n .split('\\n')\n .map((line) => line.trim())\n .filter(Boolean);
Modern Yarn formats error detail fields such as
Response Codewith ANSI color sequences and OSC 8 hyperlinks before passing them toStreamReport, which serializes the formatted strings verbatim into its JSON line output. When colors are enabled, such as by default on GitHub Actions even over non-TTY pipes or viaFORCE_COLORand.yarnrc.ymlsettings, escape codes appear around both theResponse Codelabel and status number. As a result,parseYarnModernErrorfailed to match the HTTP status code, fell back to the genericYN0035code instead ofE404for missing packages, and leaked raw control sequences into the parsed summary and detail text.Strip VT control characters from modern Yarn error messages prior to matching an anchored
Response Codeline, and ignore 2xx status codes for consistency with the Yarn Classic parser. In addition, split multi-line error payloads such asYN0001exception stack traces sosummaryonly retains the first line while remaining lines move intodetail, fall back toUNKNOWN_ERRORwhendisplayNameis an empty string (whenenableMessageNamesis disabled), and returnnulldirectly when no JSON error lines are present instead of delegating toparseNpmLikeErroron every successful command output.