Fix unreachable dolt-login hint on PermissionDenied push errors#11274
Open
kevglynn wants to merge 1 commit into
Open
Fix unreachable dolt-login hint on PermissionDenied push errors#11274kevglynn wants to merge 1 commit into
kevglynn wants to merge 1 commit into
Conversation
The hint text in handlePushError ("have you logged into DoltHub using
'dolt login'?") was unreachable due to two bugs:
1. The sentinel ErrUnknownPushErr was compared with switch/== but
PushToRemoteBranch wraps it via fmt.Errorf("%w; %s", ...), so the
equality check never matched. Fixed: use errors.Is.
2. The gRPC status was stringified (%s) in the same wrap, so
status.FromError could never extract codes.PermissionDenied. Fixed:
use %w to preserve the original error in the chain, and extract the
status from RpcError via errors.As.
Also fixes the RpcError type assertion (err.(*RpcError)) which suffered
the same wrapping issue — now uses errors.As.
Closes dolthub#783
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
handlePushError("have you logged into DoltHub using 'dolt login'?") has been unreachable sincePushToRemoteBranchstarted wrappingErrUnknownPushErr— the sentinel comparison usedswitch/==on a wrapped error, and the gRPC status was stringified sostatus.FromErrorcouldn't seecodes.PermissionDeniedRpcErrortype assertion in the same function, which suffered the same wrapping issue (theFullDetails()code path was similarly dead)Changes
go/libraries/doltcore/env/actions/remotes.go: Changedfmt.Errorf("%w; %s", ErrUnknownPushErr, err.Error())tofmt.Errorf("%w: %w", ErrUnknownPushErr, err)— preserves both the sentinel and the original error (includingRpcErrorwith its captured gRPC status) in the chaingo/cmd/dolt/commands/push.go: Replacedswitch err/err.(*RpcError)witherrors.Is/errors.As; extractedisPermissionDeniedErrhelper that checks theRpcErrorstatus viaerrors.As, falling back to error text matchinggo/cmd/dolt/commands/push_test.go: 6 test cases forisPermissionDeniedErrcovering wrappedRpcErrorwith PermissionDenied, Internal, and Unauthenticated codes; plain text matching; non-matching errors; nilTest plan
go test -run TestIsPermissionDeniedErr ./cmd/dolt/commands/ -v— all 6 cases passgo test ./cmd/dolt/commands/— full package passesgo test ./libraries/doltcore/env/actions/— passes (error format change)go test ./libraries/doltcore/remotestorage/— passesgo vet ./cmd/dolt/commands/— cleanCloses #783
Made with Cursor