Skip to content

fix(refactor): create new error output primitives - #7515

Merged
lukekarrys merged 2 commits into
latestfrom
lk/errors-and-json
May 13, 2024
Merged

fix(refactor): create new error output primitives#7515
lukekarrys merged 2 commits into
latestfrom
lk/errors-and-json

Conversation

@lukekarrys

@lukekarryslukekarrys commented May 13, 2024

Copy link
Copy Markdown
Contributor

These will be used to generate normal and json error messages in the same format from both commands and the exit handler.

This also does a few others things:

  • makes did-you-mean take a package so it can be sync and called more easily from the error handlers
  • standardize all error messages with 2 space indentation to match the rest of npm

@npm-cli-bot

npm-cli-bot commented May 13, 2024

Copy link
Copy Markdown
Collaborator

no statistically significant performance changes detected

timing results
app-largecleanlock-onlycache-onlymodules-onlyno-lockno-cacheno-modulesno-cleanshow-versionrun-scriptcache-only
peer-deps
no-clean
audit
npm@latest30.291 ±0.5010.688 ±0.0411.786 ±0.041.585 ±0.021.561 ±0.011.294 ±0.018.280 ±0.011.315 ±0.020.139 ±0.000.166 ±0.0013.501 ±0.063.679 ±2.23
#751532.727 ±0.8810.693 ±0.0311.727 ±0.041.569 ±0.021.548 ±0.011.266 ±0.008.218 ±0.021.283 ±0.000.140 ±0.000.167 ±0.0014.762 ±0.162.153 ±0.01
app-mediumcleanlock-onlycache-onlymodules-onlyno-lockno-cacheno-modulesno-cleanshow-versionrun-scriptcache-only
peer-deps
no-clean
audit
npm@latest23.548 ±0.007.949 ±0.048.943 ±0.091.528 ±0.021.526 ±0.011.463 ±0.045.823 ±0.001.339 ±0.010.140 ±0.000.167 ±0.009.434 ±0.053.167 ±1.71
#751523.178 ±0.057.946 ±0.028.920 ±0.031.540 ±0.031.499 ±0.001.427 ±0.015.772 ±0.081.309 ±0.020.138 ±0.000.164 ±0.009.849 ±0.041.972 ±0.01

Comment threadlib/utils/did-you-mean.js Outdated
Comment threadlib/commands/run-script.js Outdated
Comment threadlib/npm.js Outdated
Comment threadlib/npm.js Outdated
Comment threadlib/utils/error-message.js Outdated
Comment threadlib/npm.js Outdated
These will be used to generate error messages from both commands and the exit handler.
Also makes the did-you-mean function take a package so it can be sync and called more easily from the error handlers.
@lukekarryslukekarrys changed the title fix(refactor): split error messaging into more fnsfix(refactor): create new error output primitivesMay 13, 2024
@lukekarrys
lukekarrys marked this pull request as ready for review May 13, 2024 06:19
@lukekarrys
lukekarrys requested a review from a team as a code ownerMay 13, 2024 06:19
],
Array [
"404",
"Note that you can also install from a",

@lukekarryslukekarrysMay 13, 2024

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

These snapshot changes don't actually change what is displayed to the user. The snapshots changed because these are unit tests.

When we format these messages consecutive calls to output with the same first param (404 in this case) are rendered identically to one call with a message that includes newlines.

module.exports = {
outputError,
jsonError,
}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

This is a separate file because these functions will get used in multiple places by #7508.

They are also separate from error-message.js because they need to be required eagerly to prevent the case of them being removed when npm updates itself.

@lukekarrys
lukekarrys merged commit b54cdb8 into latestMay 13, 2024
@lukekarrys
lukekarrys deleted the lk/errors-and-json branch May 13, 2024 17:24
@github-actionsgithub-actionsBot mentioned this pull request May 13, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@lukekarrys@npm-cli-bot@wraithgar