From 9762cdf47eb9afdcb22048dfb8651b967d459eb8 Mon Sep 17 00:00:00 2001 From: mdrakos Date: Thu, 9 Nov 2023 13:39:53 -0800 Subject: [PATCH] Add headless recognition to requirement operations --- internal/runbits/rationalize/types.go | 2 ++ internal/runbits/requirements/rationalize.go | 11 +++++++++++ internal/runbits/requirements/requirements.go | 3 +++ 3 files changed, 16 insertions(+) diff --git a/internal/runbits/rationalize/types.go b/internal/runbits/rationalize/types.go index 264794e7fa..51a69035f6 100644 --- a/internal/runbits/rationalize/types.go +++ b/internal/runbits/rationalize/types.go @@ -17,6 +17,8 @@ var ErrNotAuthenticated = errors.New("not authenticated") var ErrActionAborted = errors.New("aborted by user") +var ErrHeadless = errors.New("headless") + type ErrAPI struct { Wrapped error Code int diff --git a/internal/runbits/requirements/rationalize.go b/internal/runbits/requirements/rationalize.go index b6babd8f84..0ad183817a 100644 --- a/internal/runbits/requirements/rationalize.go +++ b/internal/runbits/requirements/rationalize.go @@ -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()) } } diff --git a/internal/runbits/requirements/requirements.go b/internal/runbits/requirements/requirements.go index 5faf07f963..4eff7aee3e 100644 --- a/internal/runbits/requirements/requirements.go +++ b/internal/runbits/requirements/requirements.go @@ -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 {