Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: show human readable errors for toggle flag and fetch environment #170

Merged
merged 23 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions internal/quickstart/create_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func (m createFlagModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case createdFlagMsg:
m.showSuccessView = true
m.existingFlagUsed = msg.existingFlagUsed
m.flag = msg.flag
case errMsg:
m.err = msg.err
Expand All @@ -98,11 +97,7 @@ func (m createFlagModel) View() string {
MarginLeft(2)

if m.showSuccessView {
successMessage := fmt.Sprintf("Flag %q created successfully!", m.flag.name)
if m.existingFlagUsed {
successMessage = fmt.Sprintf("Using existing flag %q for setup.", m.flag.name)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code path doesn't get run anymore as of PR #179

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like that's a bug. Can you add existingFlag = true in the createFlag command after checking if !msgRequestErr.IsConflict()? That would mean there is an error and it's a conflict error, so we want to set the variable to true.

return successMessage + " Press enter to continue."
return fmt.Sprintf("Flag %q created successfully! Press enter to continue.", m.flag.name)
}

return fmt.Sprintf(
Expand Down
7 changes: 2 additions & 5 deletions internal/quickstart/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func toggleFlag(client flags.Client, accessToken, baseUri, flagKey string, enabl
}

type createdFlagMsg struct {
flag flag
existingFlagUsed bool
flag flag
}

type confirmedFlagMsg struct {
Expand Down Expand Up @@ -91,8 +90,6 @@ func (e msgRequestError) IsConflict() bool {

func createFlag(client flags.Client, accessToken, baseUri, flagName, flagKey, projKey string) tea.Cmd {
return func() tea.Msg {
var existingFlag bool

_, err := client.Create(
context.Background(),
accessToken,
Expand Down Expand Up @@ -122,7 +119,7 @@ func createFlag(client flags.Client, accessToken, baseUri, flagName, flagKey, pr
return createdFlagMsg{flag: flag{
key: flagKey,
name: flagName,
}, existingFlagUsed: existingFlag}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exisitingFlagUsed wasn't getting used anymore so I removed references to it.

}}
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/quickstart/toggle_flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (m toggleFlagModel) View() string {
toggle = "ON"
}

if m.flagWasEnabled {
if m.flagWasEnabled && m.err == nil {
furtherInstructions = fmt.Sprintf("\n\nCheck your %s to see the change!", logTypeMap[m.sdkKind])
}
Comment on lines -95 to 97
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevent showing the success message when there is an error.


Expand Down
Loading