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

Conversation

yannbf
Copy link
Member

@yannbf yannbf commented Oct 28, 2024

What I did

This PR improves the parsing logic from NPMProxy so that it can detect different patterns from different versions of NPM.
I experienced this issue while QAing the new version of Storybook and having some issues which would just show a generic NPM error message instead of providing more insights.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 77.6 MB 77.6 MB 0 B -0.42 0%
initSize 143 MB 143 MB 34 B -4.07 0%
diffSize 65.1 MB 65.1 MB 34 B -4.34 0%
buildSize 6.82 MB 6.82 MB 0 B -0.57 0%
buildSbAddonsSize 1.51 MB 1.51 MB 0 B -0.6 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.85 MB 1.85 MB 0 B 0.42 0%
buildSbPreviewSize 271 kB 271 kB 0 B 0.41 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.83 MB 3.83 MB 0 B -0.58 0%
buildPreviewSize 3 MB 3 MB 0 B 0.19 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 7.2s 7.9s 641ms -0.57 8.1%
generateTime 21.9s 23.8s 1.9s 0.89 8%
initTime 15.8s 17.7s 1.9s 2.05 🔺10.7%
buildTime 9.9s 8.7s -1s -193ms -1.17 -13.6%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 6.6s 4.9s -1s -711ms -1.78 🔰-34.6%
devManagerResponsive 4s 3.1s -906ms -2.1 🔰-28.9%
devManagerHeaderVisible 621ms 501ms -120ms -1.09 -24%
devManagerIndexVisible 710ms 573ms -137ms -0.85 -23.9%
devStoryVisibleUncached 1s 941ms -104ms -0.63 -11.1%
devStoryVisible 709ms 536ms -173ms -1 -32.3%
devAutodocsVisible 521ms 445ms -76ms -1.17 -17.1%
devMDXVisible 543ms 438ms -105ms -1.24 🔰-24%
buildManagerHeaderVisible 558ms 472ms -86ms -1.59 🔰-18.2%
buildManagerIndexVisible 576ms 481ms -95ms -1.73 🔰-19.8%
buildStoryVisible 557ms 466ms -91ms -1.87 🔰-19.5%
buildAutodocsVisible 484ms 394ms -90ms -1.56 🔰-22.8%
buildMDXVisible 463ms 389ms -74ms -1.47 🔰-19%

Greptile Summary

This PR improves NPM error parsing in Storybook's package manager implementation, enhancing error message clarity and handling different NPM version formats.

  • Updated NPM_ERROR_REGEX in NPMProxy.ts to handle both legacy ('npm ERR!') and modern ('npm error') formats
  • Added comprehensive error code mappings in NPMProxy.ts for better error message clarity
  • Added test cases in NPMProxy.test.ts for different error formats including timeout errors
  • Improved error message extraction by adjusting regex capture group references
  • Enhanced error handling to provide more specific feedback instead of generic "NPM error" messages

This commit refactors the error parsing logic in the NPMProxy class. It updates the regular expression used to match npm errors and extracts the error code from the error message. This change improves the accuracy of error handling in the NPMProxy class.
@yannbf yannbf added bug cli patch:yes Bugfix & documentation PR that need to be picked to main branch ci:normal labels Oct 28, 2024
@yannbf yannbf self-assigned this Oct 28, 2024
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Copy link

nx-cloud bot commented Oct 28, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 13c9a20. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@yannbf yannbf merged commit a4b4267 into next Oct 30, 2024
61 of 65 checks passed
@yannbf yannbf deleted the yann/fix-npm-error-parsing branch October 30, 2024 08:36
@kasperpeulen kasperpeulen removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants