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

Recognize headless errors on requirement operations #2876

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions internal/runbits/rationalize/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var ErrNotAuthenticated = errors.New("not authenticated")

var ErrActionAborted = errors.New("aborted by user")

var ErrHeadless = errors.New("headless")
Copy link
Contributor

Choose a reason for hiding this comment

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

I view errors in this file as "global" errors. Is this going to be used outside the internal/runbits/requirements package? If not, we should put it in that package and remove it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Never mind, I think this will be used in user-facing errors for requirement operations like install/uninstall.


type ErrAPI struct {
Wrapped error
Code int
Expand Down
11 changes: 11 additions & 0 deletions internal/runbits/requirements/rationalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,20 @@ func (r *RequirementOperation) rationalizeError(err *error) {
buildPlannerErr.LocalizedError(),
errs.SetIf(buildPlannerErr.InputError(), errs.SetInput()))

// Project not found
case errors.Is(*err, rationalize.ErrNoProject):
*err = errs.WrapUserFacing(*err,
locale.Tr("err_no_project"),
errs.SetInput())

// Headless
case errors.Is(*err, rationalize.ErrHeadless):
*err = errs.WrapUserFacing(*err,
locale.Tl(
"err_requirement_headless",
"Cannot update requirements for a headless project. Please visit {{.V0}} to convert your project and try again.",
r.Project.URL(),
),
errs.SetInput())
}
}
3 changes: 3 additions & 0 deletions internal/runbits/requirements/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ
if r.Project == nil {
return rationalize.ErrNoProject
}
if r.Project.IsHeadless() {
return rationalize.ErrHeadless
}
out.Notice(locale.Tl("operating_message", "", r.Project.NamespaceString(), r.Project.Dir()))

switch nsType {
Expand Down
Loading