Skip to content

Commit b265096

Browse files
authored
Merge pull request #2114 from ActiveState/mitchell/dx-1252
Show a "default project no longer exists" error message for state shell too when applicable
2 parents ab79d6b + 2a6743f commit b265096

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

internal/locale/locales/en-us.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,8 @@ arg_state_use_namespace_description:
18961896
other: "The org/project namespace of the project that you wish to use, or just the project name if previously checked out using [ACTIONABLE]`state checkout`[/RESET]."
18971897
err_use_commit_id_mismatch:
18981898
other: "Cannot switch to the given commit ID. Please use [ACTIONABLE]`state checkout`[/RESET] to check out a specific commit ID and then try again."
1899+
err_use_default_project_does_not_exist:
1900+
other: "The default project no longer exists. Please either check it out again with [ACTIONABLE]state checkout[/RESET] or run [ACTIONABLE]state use reset[/RESET] to unset your default project."
18991901
err_shell_commit_id_mismatch:
19001902
other: "Cannot start a shell/prompt for the given commit ID. Please use [ACTIONABLE]`state checkout`[/RESET] to check out a specific commit ID and then try again."
19011903
err_shell_cannot_load_project:

internal/runners/shell/shell.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package shell
33
import (
44
"github.com/ActiveState/cli/internal/analytics"
55
"github.com/ActiveState/cli/internal/config"
6+
"github.com/ActiveState/cli/internal/errs"
67
"github.com/ActiveState/cli/internal/locale"
78
"github.com/ActiveState/cli/internal/logging"
89
"github.com/ActiveState/cli/internal/output"
@@ -18,6 +19,7 @@ import (
1819
"github.com/ActiveState/cli/pkg/platform/runtime/setup"
1920
"github.com/ActiveState/cli/pkg/platform/runtime/target"
2021
"github.com/ActiveState/cli/pkg/project"
22+
"github.com/ActiveState/cli/pkg/projectfile"
2123
)
2224

2325
type Params struct {
@@ -62,6 +64,9 @@ func (u *Shell) Run(params *Params) error {
6264

6365
proj, err := findproject.FromInputByPriority("", params.Namespace, u.config, u.prompt)
6466
if err != nil {
67+
if errs.Matches(err, &projectfile.ErrorNoProject{}) {
68+
return locale.WrapError(err, "err_use_default_project_does_not_exist")
69+
}
6570
return locale.WrapError(err, "err_shell_cannot_load_project")
6671
}
6772

internal/runners/use/show.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ func (s *Show) Run() error {
4444
proj, err := project.FromPath(projectDir)
4545
if err != nil {
4646
if errs.Matches(err, &projectfile.ErrorNoProject{}) {
47-
return locale.WrapError(err,
48-
"err_use_show_default_project_does_not_exist",
49-
"The default project no longer exists. Please either check it out again with [ACTIONABLE]state checkout[/RESET] or run [ACTIONABLE]state use reset[/RESET] to unset your default project.")
47+
return locale.WrapError(err, "err_use_default_project_does_not_exist")
5048
}
5149
return locale.WrapError(err, "err_use_show_get_project", "Could not get default project.")
5250
}

test/integration/shell_int_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package integration
22

33
import (
4+
"os"
45
"path/filepath"
56
"runtime"
67
"testing"
@@ -157,6 +158,34 @@ func (suite *ShellIntegrationTestSuite) TestCd() {
157158
cp.ExpectExitCode(0)
158159
}
159160

161+
func (suite *ShellIntegrationTestSuite) TestDefaultNoLongerExists() {
162+
suite.OnlyRunForTags(tagsuite.Shell)
163+
164+
ts := e2e.New(suite.T(), false)
165+
defer ts.Close()
166+
167+
cp := ts.SpawnWithOpts(
168+
e2e.WithArgs("checkout", "ActiveState-CLI/Python3"),
169+
e2e.AppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false"),
170+
)
171+
cp.Expect("Checked out project")
172+
cp.ExpectExitCode(0)
173+
174+
cp = ts.SpawnWithOpts(
175+
e2e.WithArgs("use", "ActiveState-CLI/Python3"),
176+
e2e.AppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false"),
177+
)
178+
cp.Expect("Switched to project")
179+
cp.ExpectExitCode(0)
180+
181+
err := os.RemoveAll(filepath.Join(ts.Dirs.Work, "Python3"))
182+
suite.Require().NoError(err)
183+
184+
cp = ts.SpawnWithOpts(e2e.WithArgs("shell"))
185+
cp.Expect("The default project no longer exists")
186+
cp.ExpectExitCode(1)
187+
}
188+
160189
func TestShellIntegrationTestSuite(t *testing.T) {
161190
suite.Run(t, new(ShellIntegrationTestSuite))
162191
}

0 commit comments

Comments
 (0)