Skip to content

fix: friendly error message when api.ngc.nvidia.com is unreachable#367

Open
robobryce wants to merge 1 commit intobrevdev:mainfrom
robobryce:fix/friendly-network-error-message
Open

fix: friendly error message when api.ngc.nvidia.com is unreachable#367
robobryce wants to merge 1 commit intobrevdev:mainfrom
robobryce:fix/friendly-network-error-message

Conversation

@robobryce
Copy link
Copy Markdown

Summary

  • Detect transport-level failures (DNS timeout, dial refused, etc.) during KAS login and token refresh, and render them as a short, actionable message instead of dumping a multi-line stack trace.
  • Suppress resty's stderr WARN/ERROR blocks on the auth client unless BREV_DEBUG_HTTP is set — cmderrors already prints a friendly user-facing message and the resty trace is just noise.

Before

brev shell craftax
2026/04/25 11:00:39.237957 WARN RESTY [error]
github.com/brevdev/brev-cli/pkg/store.NewAuthHTTPClient.func1
/go/src/github.com/brevdev/brev-cli/pkg/store/http.go:164
: [error]
github.com/brevdev/brev-cli/pkg/auth.LoginAuth.GetAccessToken
/go/src/github.com/brevdev/brev-cli/pkg/auth/auth.go:33
[…30 more lines…]
: error sending token request: Get "https://api.ngc.nvidia.com/token": dial tcp: lookup api.ngc.nvidia.com on [::1]:53: read udp [::1]:51765->[::1]:53: i/o timeout

After

Could not reach api.ngc.nvidia.com — check your internet connection and try again
Verify you can resolve api.ngc.nvidia.com and that no firewall or proxy is blocking it. If the host is reachable, the service may be temporarily unavailable.

Implementation

  • pkg/errors/errors.go — new NetworkError type plus IsNetworkError, HostFromURLError, WrapNetworkError helpers.
  • pkg/auth/kas.go — wrap client.Do failures in MakeLoginCall and retrieveIDToken with WrapNetworkError, deriving the host from BaseURL.
  • pkg/cmd/cmderrors/cmderrors.go — handle *NetworkError in the type switch: render in yellow with directive, skip Sentry reporting.
  • pkg/store/http.go — install a silent resty logger on the auth HTTP client when not in debug mode.

Test plan

  • go test ./pkg/errors/... — 13 tests pass (table-driven IsNetworkError, host extraction, wrap behavior, message content, Unwrap/errors.Is chain, real httptest.Server integration, pkgerrors.Cause survival through WrapAndTrace).
  • go test ./pkg/auth/... — 12 tests pass including new TestMakeLoginCall_NetworkError, TestRetrieveIDToken_NetworkError, TestRetrieveIDToken_NonNetworkErrorUnchanged, and Test_hostFromURL.
  • go test ./pkg/cmd/cmderrors/... — captures stderr to assert friendly rendering with no [error]/github.com/brevdev/... lines, and that plain errors still render through.
  • go test ./pkg/store/... and go vet ./... clean across the entire module.

🤖 Generated with Claude Code

Network failures (DNS timeout, dial refused) during login or token
refresh used to surface a multi-line stack trace plus repeated resty
WARN/ERROR blocks. Detect transport-level errors at the auth boundary
and render them as a short, actionable message with a directive.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@robobryce robobryce requested a review from a team as a code owner April 25, 2026 16:49
@brycelelbach
Copy link
Copy Markdown
Contributor

@patelspratik I think this is a better user facing diagnostic, but not sure, thoughts?

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

❌ Patch coverage is 87.83784% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.72%. Comparing base (9e0e34b) to head (ebb6a68).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/errors/errors.go 88.00% 4 Missing and 2 partials ⚠️
pkg/store/http.go 66.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #367      +/-   ##
==========================================
+ Coverage   18.18%   18.72%   +0.54%     
==========================================
  Files         140      140              
  Lines       18684    18763      +79     
==========================================
+ Hits         3398     3514     +116     
+ Misses      14912    14865      -47     
- Partials      374      384      +10     
Flag Coverage Δ
Linux 18.72% <87.83%> (+0.54%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to 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.

2 participants