You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add additional error context for HelperSubprocessFailed Sentry errors - #16967
When npm, pnpm or Yarn commands fail (including Yarn YN0001), the resulting HelperSubprocessFailed errors have no safe debugging context, so these failures are hard to triage. This PR attaches three safe error-context keys to those errors using ErrorReportContext.attach:
Key
Example
Source
command-name
pnpm install, yarn up, npm
The package manager name plus the first word of the command, only if it is on an allowlist (add, audit, config, dedupe, exec, info, install, list, outdated, remove, up, update, upgrade, view, why). Otherwise only the package manager name is sent.
package-manager-version
10.9.2
See "Where the package manager version comes from" below.
registry-host
registry.npmjs.org
Host only, from npm_config_registry in the Corepack env, or else from RegistryHelper#registry_url. Left out if it cannot be parsed safely.
Where the package manager version comes from
No extra subprocess runs after a failure. The version comes from information Dependabot already has:
Exact selector: if the command runs through an exact Corepack selector such as npm@10.8.2, that version is used.
Version Dependabot already looked up:PackageManagerHelper#installed_version already runs corepack <pm> -v through Helpers.package_manager_version. That method now also records the result in a per-thread store, keyed by the exact name it ran (npm, yarn, pnpm@8, npm@10). When a command fails, we look up the version recorded under the same name.
Otherwise the key is left out. For example, if installed_version fell back to the lockfile without running corepack <pm> -v, nothing is recorded, so we don't report a guessed version.
The store is per thread, like the existing dependency_files and npm_version_selector state in Helpers.
Changes
New NpmAndYarn::SubprocessErrorContext: the subcommand allowlist and the attach logic, including the registry host check.
Helpers:
Wraps the four places that run npm, pnpm and Yarn commands (run_npm_command, run_selected_pnpm, run_single_yarn_command, package_manager_run_command). It rescues HelperSubprocessFailed, attaches the context and re-raises the original error.
package_manager_version records the versions it looks up.
If attaching the context fails for any reason, the original error is still raised and a warning is logged.
RegistryHelper#registry_url: a new public method that returns the configured registry, or https://registry.npmjs.org. It makes no network calls; unlike find_corepack_env_variables, it never fetches integrity keys.
Anything you want to highlight for special attention from reviewers?
Why not run --version or config get after a failure? Many of these failures are expected and rescued (for example in version_resolver.rb). Extra commands there would add latency to normal update runs and could fail themselves. Reusing the version Dependabot already looked up costs nothing.
What is never sent: command lines, arguments, paths, full registry URLs, credentials and stderr. Specs check this.
Caveat: for npm without a selector, Dependabot runs the local npm binary, while the recorded version comes from corepack npm -v. raise_unless_local_npm_major_matches! ensures the major versions match, so the reported version is accurate to the major version.
Nested calls: a command that goes through two wrapped methods (for example, the npm selector path calls package_manager_run_command) gets the context attached once.
Bun:bun/lib/dependabot/bun/helpers.rb#run_bun_command is a separate implementation with no Corepack or registry handling, so it isn't changed here. It is tracked as a follow-up.
Why the version store is in Helpers:PackageManagerHelper is already at the Metrics/ClassLength limit, so the store lives in Helpers, which already holds similar per-thread state.
How will you know you've accomplished your goal?
New specs check the result of ErrorReportContext.build for each case:
helpers_spec.rb:
npm with a private .npmrc registry
pnpm@8 reports its version; pnpm@7 leaves the version out
an exact npm@10.8.2 selector
Yarn YN0001 reports yarn up, 4.5.0 and registry.npmjs.org
a non-allowlisted command reports only pnpm
the original error is re-raised if attaching fails
the version is recorded by package_manager_version
subprocess_error_context_spec.rb: the allowlist, nothing sensitive leaking, a registry URL that can't be parsed, and a missing version or registry.
registry_helper_spec.rb:#registry_url from .npmrc, from a replaces-base credential (no network calls), and the default registry.
Checklist
I have run the complete test suite to ensure all tests and linters pass.
I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
I have written clear and descriptive commit messages.
I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
I have ensured that the code is well-documented and easy to understand.
Only report whole semver versions so command output that starts with a
version cannot leak credentials or paths, and key recorded versions by
working directory, project and runnable name so failures never report a
version observed for another project or runtime. Also record versions
from in-project -v/--version probes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 42070f36-d24f-4896-beb6-a42a798b2c99
Clear the version cache before seeding these examples. The memoization example in package_manager_helper_spec.rb:973–983 records pnpm@7 as 7.1.0 under the same working-directory/no-manifest key, and the shared cleanup does not clear this cache. With randomized ordering, the new “omits the version when none was read” example can inherit that value and fail if it runs first in this group; resetting the cache here isolates it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
When npm, pnpm or Yarn commands fail (including Yarn
YN0001), the resultingHelperSubprocessFailederrors have no safe debugging context, so these failures are hard to triage. This PR attaches three safeerror-contextkeys to those errors usingErrorReportContext.attach:command-namepnpm install,yarn up,npmadd,audit,config,dedupe,exec,info,install,list,outdated,remove,up,update,upgrade,view,why). Otherwise only the package manager name is sent.package-manager-version10.9.2registry-hostregistry.npmjs.orgnpm_config_registryin the Corepack env, or else fromRegistryHelper#registry_url. Left out if it cannot be parsed safely.Where the package manager version comes from
No extra subprocess runs after a failure. The version comes from information Dependabot already has:
npm@10.8.2, that version is used.PackageManagerHelper#installed_versionalready runscorepack <pm> -vthroughHelpers.package_manager_version. That method now also records the result in a per-thread store, keyed by the exact name it ran (npm,yarn,pnpm@8,npm@10). When a command fails, we look up the version recorded under the same name.installed_versionfell back to the lockfile without runningcorepack <pm> -v, nothing is recorded, so we don't report a guessed version.The store is per thread, like the existing
dependency_filesandnpm_version_selectorstate inHelpers.Changes
NpmAndYarn::SubprocessErrorContext: the subcommand allowlist and the attach logic, including the registry host check.Helpers:run_npm_command,run_selected_pnpm,run_single_yarn_command,package_manager_run_command). It rescuesHelperSubprocessFailed, attaches the context and re-raises the original error.package_manager_versionrecords the versions it looks up.RegistryHelper#registry_url: a new public method that returns the configured registry, orhttps://registry.npmjs.org. It makes no network calls; unlikefind_corepack_env_variables, it never fetches integrity keys.Anything you want to highlight for special attention from reviewers?
--versionorconfig getafter a failure? Many of these failures are expected and rescued (for example inversion_resolver.rb). Extra commands there would add latency to normal update runs and could fail themselves. Reusing the version Dependabot already looked up costs nothing.npmbinary, while the recorded version comes fromcorepack npm -v.raise_unless_local_npm_major_matches!ensures the major versions match, so the reported version is accurate to the major version.package_manager_run_command) gets the context attached once.bun/lib/dependabot/bun/helpers.rb#run_bun_commandis a separate implementation with no Corepack or registry handling, so it isn't changed here. It is tracked as a follow-up.Helpers:PackageManagerHelperis already at theMetrics/ClassLengthlimit, so the store lives inHelpers, which already holds similar per-thread state.How will you know you've accomplished your goal?
New specs check the result of
ErrorReportContext.buildfor each case:helpers_spec.rb:.npmrcregistrynpm@10.8.2selectorYN0001reportsyarn up,4.5.0andregistry.npmjs.orgpnpmpackage_manager_versionsubprocess_error_context_spec.rb: the allowlist, nothing sensitive leaking, a registry URL that can't be parsed, and a missing version or registry.registry_helper_spec.rb:#registry_urlfrom.npmrc, from areplaces-basecredential (no network calls), and the default registry.Checklist