-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of user-facing errors for
state install
and …
…`state uninstall`.
- Loading branch information
1 parent
24ecbdc
commit 52dc826
Showing
7 changed files
with
113 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package packages | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ActiveState/cli/internal/errs" | ||
"github.com/ActiveState/cli/internal/locale" | ||
"github.com/ActiveState/cli/internal/runbits/rationalize" | ||
bpModel "github.com/ActiveState/cli/pkg/platform/api/buildplanner/model" | ||
"github.com/ActiveState/cli/pkg/platform/authentication" | ||
"github.com/ActiveState/cli/pkg/platform/runtime/buildexpression" | ||
) | ||
|
||
func rationalizeError(auth *authentication.Auth, err *error) { | ||
var commitError *bpModel.CommitError | ||
var requirementNotFoundErr *buildexpression.RequirementNotFoundError | ||
|
||
switch { | ||
case err == nil: | ||
return | ||
|
||
// No activestate.yaml. | ||
case errors.Is(*err, rationalize.ErrNoProject): | ||
*err = errs.WrapUserFacing(*err, | ||
locale.T("err_no_project"), | ||
errs.SetInput(), | ||
) | ||
|
||
// Error staging a commit during install. | ||
case errors.As(*err, &commitError): | ||
switch commitError.Type { | ||
case bpModel.NotFoundErrorType: | ||
*err = errs.WrapUserFacing(*err, | ||
locale.Tl("err_packages_not_found", "Could not make runtime changes because your project was not found."), | ||
errs.SetInput(), | ||
errs.SetTips(locale.T("tip_private_project_auth")), | ||
) | ||
case bpModel.HeadOnBranchMovedErrorType: | ||
*err = errs.WrapUserFacing(*err, | ||
locale.T("err_buildplanner_head_on_branch_moved"), | ||
errs.SetInput(), | ||
) | ||
case bpModel.NoChangeSinceLastCommitErrorType: | ||
*err = errs.WrapUserFacing(*err, | ||
locale.Tl("err_packages_exists", "That package is already installed"), | ||
errs.SetInput(), | ||
) | ||
} | ||
|
||
// Requirement not found for uninstall. | ||
case errors.As(*err, &requirementNotFoundErr): | ||
*err = errs.WrapUserFacing(*err, | ||
locale.Tr("err_remove_requirement_not_found", requirementNotFoundErr.Name), | ||
errs.SetInput(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters