Skip to content

Commit dc7ac6b

Browse files
zeroshadeCopilot
andauthored
fix: restore hints when unauthorized (#321)
## Summary Restores helpful hints that were lost in the error handling refactor (#279): - Added hint for `ErrUnauthorized`: "Did you run `dbc auth login`?" - Restored simpler hint for `ErrUnauthorizedColumnar` with original wording from #255 ## Context These hints were originally added in #255 to help users troubleshoot authorization issues when installing private drivers. During the error handling refactor in #279, these hints were either removed or changed to more verbose messages. ## Changes - `cmd/dbc/main.go`: Updated `formatErr()` function to include both helpful hints Fixes #315 --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: zeroshade <555095+zeroshade@users.noreply.github.com>
1 parent 74d43a2 commit dc7ac6b

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

cmd/dbc/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ func formatErr(err error) string {
153153
case errors.Is(err, auth.ErrNoTrialLicense):
154154
return errStyle.Render("Could not download license, trial not started")
155155
case errors.Is(err, dbc.ErrUnauthorized):
156-
return errStyle.Render(err.Error())
156+
return errStyle.Render(err.Error()) + "\n" +
157+
msgStyle.Render("Did you run `dbc auth login`?")
157158
case errors.Is(err, dbc.ErrUnauthorizedColumnar):
158159
return errStyle.Render(err.Error()) + "\n" +
159160
msgStyle.Render("Installing this driver requires a license. Verify you have an active license at https://console.columnar.tech/licenses and try this command again. Contact support@columnar.tech if you believe this is an error.")

cmd/dbc/main_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,55 @@ package main
1717
import (
1818
"bytes"
1919
"context"
20+
"fmt"
21+
"strings"
2022
"testing"
2123
"time"
2224

2325
tea "github.com/charmbracelet/bubbletea"
26+
"github.com/columnar-tech/dbc"
2427
"github.com/stretchr/testify/require"
2528
)
2629

30+
func TestFormatErr(t *testing.T) {
31+
tests := []struct {
32+
name string
33+
err error
34+
wantSubstring []string
35+
}{
36+
{
37+
name: "ErrUnauthorized direct",
38+
err: dbc.ErrUnauthorized,
39+
wantSubstring: []string{dbc.ErrUnauthorized.Error(), "Did you run `dbc auth login`?"},
40+
},
41+
{
42+
name: "ErrUnauthorized wrapped",
43+
err: fmt.Errorf("operation failed: %w", dbc.ErrUnauthorized),
44+
wantSubstring: []string{dbc.ErrUnauthorized.Error(), "Did you run `dbc auth login`?"},
45+
},
46+
{
47+
name: "ErrUnauthorizedColumnar direct",
48+
err: dbc.ErrUnauthorizedColumnar,
49+
wantSubstring: []string{dbc.ErrUnauthorizedColumnar.Error(), "active license", "support@columnar.tech"},
50+
},
51+
{
52+
name: "ErrUnauthorizedColumnar wrapped",
53+
err: fmt.Errorf("operation failed: %w", dbc.ErrUnauthorizedColumnar),
54+
wantSubstring: []string{dbc.ErrUnauthorizedColumnar.Error(), "active license", "support@columnar.tech"},
55+
},
56+
}
57+
58+
for _, tt := range tests {
59+
t.Run(tt.name, func(t *testing.T) {
60+
got := formatErr(tt.err)
61+
for _, want := range tt.wantSubstring {
62+
require.True(t, strings.Contains(got, want),
63+
"formatErr(%v) = %q, expected to contain %q", tt.err, got, want)
64+
}
65+
})
66+
}
67+
}
68+
2769
func TestCmdStatus(t *testing.T) {
2870
tests := []struct {
2971
name string

0 commit comments

Comments
 (0)