Skip to content

Commit 1c50382

Browse files
authored
Merge pull request #2110 from ActiveState/mitchell/dx-1237
`state use show` shows a better error message if the default project has been deleted
2 parents c3ed7de + 3f4f01b commit 1c50382

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

internal/runners/use/show.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package use
33
import (
44
"github.com/ActiveState/cli/internal/config"
55
"github.com/ActiveState/cli/internal/constants"
6+
"github.com/ActiveState/cli/internal/errs"
67
"github.com/ActiveState/cli/internal/locale"
78
"github.com/ActiveState/cli/internal/output"
89
"github.com/ActiveState/cli/pkg/project"
10+
"github.com/ActiveState/cli/pkg/projectfile"
911
)
1012

1113
type Show struct {
@@ -41,6 +43,11 @@ func (s *Show) Run() error {
4143

4244
proj, err := project.FromPath(projectDir)
4345
if err != nil {
46+
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.")
50+
}
4451
return locale.WrapError(err, "err_use_show_get_project", "Could not get default project.")
4552
}
4653

test/integration/use_int_test.go

Lines changed: 8 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"
@@ -197,6 +198,13 @@ func (suite *UseIntegrationTestSuite) TestShow() {
197198
}
198199
cp.ExpectExitCode(0)
199200

201+
err := os.RemoveAll(projectDir)
202+
suite.Require().NoError(err)
203+
204+
cp = ts.SpawnWithOpts(e2e.WithArgs("use", "show"))
205+
cp.ExpectLongString("The default project no longer exists")
206+
cp.ExpectExitCode(1)
207+
200208
cp = ts.SpawnWithOpts(e2e.WithArgs("use", "reset", "--non-interactive"))
201209
cp.Expect("Reset")
202210
cp.ExpectExitCode(0)

0 commit comments

Comments
 (0)