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

User facing errors for State Checkout #2776

Merged
merged 5 commits into from
Oct 3, 2023
Merged

User facing errors for State Checkout #2776

merged 5 commits into from
Oct 3, 2023

Conversation

Naatan
Copy link
Member

@Naatan Naatan commented Sep 28, 2023

StoryDX-2008 User facing errors for state checkout

@github-actions github-actions bot changed the base branch from master to version/0-42-0-RC1 September 28, 2023 17:29
Copy link
Member

@MDrakos MDrakos left a comment

Choose a reason for hiding this comment

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

Overall this looks really good. Just a few points.

@@ -27,19 +28,24 @@ func (e *userFacingError) ErrorTips() []string {
return e.tips
}

func (e *userFacingError) InputError() bool {
Copy link
Member

Choose a reason for hiding this comment

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

If I recall correctly from my previous PR we wanted to avoid user facing errors from colliding with existing error implementations. This is an implementation of the ErrorInput interface from the locale package.

Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't a collision. The problem I ran into is wanting to communicate an input failure on the user facing error side. So when I asserted the type I could set the user facing error, but also assert that it is due to user input.

If we use WrapInputError or something like that we add even more errors to the stack, and the API would be pretty awkward. This solves both those problems, you can now set a user facing error as an input error with NewUserFacing(msg, SetInput(true))

other: The requested project [NOTICE]{{.V0}}[/RESET] does not exist under [NOTICE]{{.V1}}[/RESET]. Please ensure the owner is correct and that the project has been created.
err_api_project_not_found_unauthenticated:
other: The requested project [NOTICE]{{.V0}}/{{.V1}}[/RESET] could not be found
other: The requested project [NOTICE]{{.V1}}[/RESET] does not exist under [NOTICE]{{.V0}}[/RESET]. Please ensure the owner is correct and that the project has been created.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Why are the variables here out of order?

Copy link
Member Author

Choose a reason for hiding this comment

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

To keep the order consistent in the code itself, see lines 43 and 46 here:

locale.NewInputError("err_api_project_not_found", "", orgName, projectName),
locale.T("tip_private_project_auth"))
}
return nil, errs.Pack(err, locale.NewInputError("err_api_project_not_found", "", orgName, projectName))

Comment on lines +29 to +34
branches, err := model.BranchNamesForProjectFiltered(proj.Owner(), proj.Name(), proj.BranchName())
if err == nil && len(branches) > 1 {
// Suggest alternate branches
*rerr = errs.NewUserFacingError(locale.Tr(
"err_alternate_branches",
errNoMatchingPlatform.HostPlatform, errNoMatchingPlatform.HostArch,
Copy link
Member

Choose a reason for hiding this comment

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

nit: While I see the value in adding this suggestion it also adds complexity where we could just provide a more generic, but still helpful, message.

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR is just hoisting the existing error up to a user facing level. It's not seeking to make changes to the actual error.

Comment on lines +7 to +9
type ErrNoProject struct {
Inner
}
Copy link
Member

Choose a reason for hiding this comment

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

Having centralized errors in a package called rationalize is a bit confusing. Is this because the error is used by the rationalized functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Rationalize is the term I want to use for this, so when you read "Rationalize" your mind should immediately make the connection.

"Centralized errors" isn't a term we ever used for this, it's just a generic way of thinking about this problem space. I want to be explicit about it.

Btw happy to explore other terms if you don't like "Rationalize". The intend is that it's both sensible and explicit.

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer not to get caught up in the naming. This makes enough sense to me.

@Naatan Naatan requested a review from MDrakos October 3, 2023 17:14
Comment on lines +7 to +9
type ErrNoProject struct {
Inner
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer not to get caught up in the naming. This makes enough sense to me.

@Naatan Naatan merged commit 8b0351d into version/0-42-0-RC1 Oct 3, 2023
13 of 21 checks passed
@Naatan Naatan deleted the DX-2008 branch October 3, 2023 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants