Repository navigation
Add host to network errors outside registry client - #16963
Merged
v-abhishekbhaskar merged 2 commits intoNov 18, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Malformed JSON from a cross-host service endpoint is attributed to the discovery host rather than the server actually queried, affecting both provider and module version lookups.
1 open issue
What changed in this PR
This PR improves Cargo and Terraform registry error diagnostics by adding host context to JSON parse failures and routing direct requests through the shared registry client.
Changes:
- Adds Cargo response helpers to classify private-registry HTTP errors and annotate JSON parse failures.
- Uses the shared registry client for Cargo metadata and package details, and Terraform package details.
- Adds regression coverage for HTTP failures, malformed responses, and host-only error context.
| File | Description |
|---|---|
terraform/spec/dependabot/terraform/registry_client_spec.rb |
Tests host context on provider-version parse failures. |
terraform/spec/dependabot/terraform/package/package_details_fetcher_spec.rb |
Tests host-only context on malformed provider responses. |
terraform/lib/dependabot/terraform/registry_client.rb |
Annotates provider and module version parse errors. |
terraform/lib/dependabot/terraform/package/package_details_fetcher.rb |
Uses shared requests and adds parse-error context. |
cargo/spec/dependabot/cargo/package/package_details_fetcher_spec.rb |
Covers public-registry parse failures and private-registry HTTP errors. |
cargo/spec/dependabot/cargo/metadata_finder_spec.rb |
Tests context on malformed crates.io responses. |
cargo/spec/dependabot/cargo/file_parser_spec.rb |
Covers sparse-registry HTTP and parse failures. |
cargo/lib/dependabot/cargo/registry_response.rb |
Adds shared status-validation and parse-error helpers. |
cargo/lib/dependabot/cargo/package/package_details_fetcher.rb |
Uses shared requests and response handling. |
cargo/lib/dependabot/cargo/metadata_finder.rb |
Uses shared requests, handles 404s, and annotates parse failures. |
cargo/lib/dependabot/cargo/file_parser.rb |
Validates sparse-registry responses before parsing. |
Review effort: Balanced
v-sachin-sandhu
approved these changes
Nov 18, 2026
v-abhishekbhaskar
force-pushed
the
abhishekbhaskar/add-error-context-network-errors
branch
from
November 18, 2026 21:24
3a0c5c4 to
286f65d
Compare
v-abhishekbhaskar
deleted the
abhishekbhaskar/add-error-context-network-errors
branch
November 18, 2026 21:56
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
Cargo and Terraform make some registry requests outside
Dependabot::RegistryClient, or parse registry responses without checking them first. When these fail, the unknown error has nohostin itserror-context, so it can't be debugged from Sentry. This is part of the work to add the host to network errors afterDependabot::ErrorReportContext.Cargo accounts for about 95% of the events:
FileParser#sparse_registry_source_details: a 403 from a sparse registry'sconfig.jsonreturns a plainForbiddenbody. That body went straight intoJSON.parse, which raisedJSON::ParserErrorwith no host.RegistryClientonly attaches the host on socket errors and timeouts, not on HTTP error responses.Package::PackageDetailsFetcher: calledExcon.getdirectly and only handled 404. Any other non-2xx response, often with an empty body, was parsed and failed. Its socket errors and timeouts also had no host.MetadataFinder: the same direct-Excon.getand unchecked-parse pattern.Terraform:
Package::PackageDetailsFetcher: calledExcon.getdirectly.RegistryClient#all_provider_versions/#all_module_versions: parsed 200 responses without guarding against non-JSON bodies.Changes:
Dependabot::Cargo::RegistryResponse:raise_for_error_status!maps 401/403 toPrivateSourceAuthenticationFailureand any other non-2xx toPrivateSourceBadResponse. These are classified errors, so they no longer count as unknown errors.with_parse_error_contextattacheshost,http-methodandhttp-statustoJSON::ParserErrorand re-raises it.Dependabot::RegistryClient.get, so socket errors and timeouts also carry the host.Dependabot::RegistryClient.get. JSON parse failures there and inall_*_versionsget the registry host attached.Only the host is ever attached, never the full URL: registry paths can contain private crate or module names.
Anything you want to highlight for special attention from reviewers?
JSON::ParserError, now withhost/http-status. Reporting a crates.io outage as a "private source" error would be misleading.PrivateSourceAuthenticationFailureinstead of carrying a host as an unknown error. This takes it out of the unknown-error bucket entirely.PrivateSourceBadResponse. Previously, error bodies that happened to be valid JSON were parsed silently and produced no versions.LatestVersionResolverrescuesStandardErroraround every call to Terraform'sPackageDetailsFetcher, so errors from that fetcher can't reach Sentry. The change there mainly addsRegistryClientdefaults (timeouts, proxy, host caching). The observed TerraformExcon::Error::Socketevents likely come from another code path.How will you know you've accomplished your goal?
file_parser_spec: sparseconfig.jsonreturns 403Forbidden→PrivateSourceAuthenticationFailure; 502 →PrivateSourceBadResponse; 200 with non-JSON →JSON::ParserErrorwithhost.package_details_fetcher_spec: crates.io 503 with an empty body →JSON::ParserErrorwithhost: crates.io; private registry 403 →PrivateSourceAuthenticationFailure; private registry 500 →PrivateSourceBadResponse.metadata_finder_spec: crates.io 502 with a non-JSON body → parse error withhost.registry_client_specandpackage_details_fetcher_spec: non-JSON registry responses → parse error withhost.Checklist