-
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.
Conform rationalize behaviour to standard
- Loading branch information
Showing
8 changed files
with
134 additions
and
70 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 |
---|---|---|
@@ -1,22 +1,15 @@ | ||
package rationalize | ||
|
||
import "errors" | ||
|
||
// Inner is just an alias because otherwise external use of this struct would not be able to construct the error | ||
// property, and we want to keep the boilerplate minimal. | ||
type Inner error | ||
|
||
type ErrNoProject struct { | ||
Inner | ||
} | ||
|
||
type ErrNotAuthenticated struct { | ||
Inner | ||
} | ||
// ErrNoProject communicates that we were unable to find an activestate.yaml | ||
var ErrNoProject = errors.New("no project") | ||
|
||
type ErrActionAborted struct { | ||
Inner | ||
} | ||
// ErrNotAuthenticated communicates that the user is not logged in | ||
var ErrNotAuthenticated = errors.New("not authenticated") | ||
|
||
type ErrPermission struct { | ||
Inner | ||
Details interface{} | ||
} | ||
var ErrActionAborted = errors.New("aborted by user") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package push | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ActiveState/cli/internal/errs" | ||
"github.com/ActiveState/cli/internal/locale" | ||
"github.com/ActiveState/cli/internal/runbits/rationalize" | ||
) | ||
|
||
func rationalizeError(err *error) { | ||
if err == nil { | ||
return | ||
} | ||
|
||
var projectNameInUseErr *errProjectNameInUse | ||
var noPermissionErr *errNoPermission | ||
|
||
switch { | ||
|
||
// Not authenticated | ||
case errors.Is(*err, rationalize.ErrNotAuthenticated): | ||
*err = errs.WrapUserFacing(*err, | ||
locale.T("err_push_not_authenticated"), | ||
errs.SetInput()) | ||
|
||
// No activestate.yaml | ||
case errors.Is(*err, rationalize.ErrNoProject): | ||
*err = errs.WrapUserFacing(*err, | ||
locale.T("err_push_headless"), | ||
errs.SetInput(), | ||
errs.SetTips( | ||
locale.T("push_push_tip_headless_init"), | ||
locale.T("push_push_tip_headless_cwd"), | ||
)) | ||
|
||
// No changes were made | ||
case errors.Is(*err, errNoChanges): | ||
*err = errs.WrapUserFacing(*err, | ||
locale.T("err_push_nocommit"), | ||
errs.SetInput(), | ||
) | ||
|
||
// Project name is already in use | ||
case errors.As(*err, &projectNameInUseErr): | ||
*err = errs.WrapUserFacing(*err, | ||
locale.Tr("err_push_create_nonunique", projectNameInUseErr.Namespace.String()), | ||
errs.SetInput(), | ||
) | ||
|
||
// Project creation aborted | ||
case errors.Is(*err, rationalize.ErrActionAborted): | ||
*err = errs.WrapUserFacing(*err, | ||
locale.T("err_push_create_project_aborted"), | ||
errs.SetInput()) | ||
|
||
// No permission to push to project | ||
case errors.As(*err, &noPermissionErr): | ||
*err = errs.WrapUserFacing(*err, | ||
locale.Tr("err_push_no_permission", noPermissionErr.Namespace.String()), | ||
errs.SetInput()) | ||
|
||
// Custom target does not have a compatible history | ||
case errors.Is(*err, errTargetInvalidHistory): | ||
*err = errs.WrapUserFacing(*err, | ||
locale.T("err_push_target_invalid_history"), | ||
errs.SetInput()) | ||
|
||
// Need to pull first | ||
case errors.Is(*err, errPullNeeded): | ||
*err = errs.WrapUserFacing(*err, | ||
locale.T("err_push_outdated"), | ||
errs.SetInput(), | ||
errs.SetTips(locale.T("err_tip_push_outdated"))) | ||
} | ||
} |
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