-
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.
Merge pull request #2877 from ActiveState/mitchell/dx-2232
Initial implementation of user-facing errors for `state install` and `state uninstall`.
- Loading branch information
Showing
7 changed files
with
124 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,68 @@ | ||
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.ForbiddenErrorType: | ||
*err = errs.WrapUserFacing(*err, | ||
locale.Tl("err_packages_forbidden", "Could not make runtime changes because you do not have permission to do so."), | ||
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(), | ||
) | ||
default: | ||
*err = errs.WrapUserFacing(*err, | ||
locale.Tl("err_packages_buildplanner_error", "Could not make runtime changes due to the following error: {{.V0}}", commitError.Message), | ||
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