Skip to content

Commit 96eca84

Browse files
authored
Merge pull request #3636 from ActiveState/mitchell/dx-3209
Show warning for runtime in use instead of erroring out.
2 parents 2007de6 + 37c8142 commit 96eca84

File tree

4 files changed

+16
-27
lines changed

4 files changed

+16
-27
lines changed

internal/locale/locales/en-us.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,10 @@ run_description:
187187
other: Run your project scripts
188188
scripts_description:
189189
other: Show project scripts
190-
runtime_setup_in_use_err:
190+
runtime_setup_in_use_warning:
191191
other: |
192-
Could not update your runtime as it is currently in use. Please stop any active runtime processes and try again. State Tool found the following processes to be using the runtime:
192+
[WARNING]Warning:[/RESET] the runtime for this project is in use, it is recommended you restart any active processes to avoid conflicts.
193+
The following processes are currently using this runtime:
193194
{{.V0}}
194195
runtime_alternative_file_transforms_err:
195196
other: "Could not apply necessary file transformations after unpacking."

internal/runbits/runtime/rationalize.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strings"
77

88
"github.com/ActiveState/cli/internal/errs"
9-
"github.com/ActiveState/cli/internal/graph"
109
"github.com/ActiveState/cli/internal/locale"
1110
buildscript_runbit "github.com/ActiveState/cli/internal/runbits/buildscript"
1211
"github.com/ActiveState/cli/internal/runbits/rationalize"
@@ -22,22 +21,13 @@ var ErrBuildscriptNotExist = buildscript_runbit.ErrBuildscriptNotExist
2221

2322
var ErrBuildScriptNeedsCommit = errors.New("buildscript is dirty, need to run state commit")
2423

25-
type RuntimeInUseError struct {
26-
Processes []*graph.ProcessInfo
27-
}
28-
29-
func (err RuntimeInUseError) Error() string {
30-
return "runtime is in use"
31-
}
32-
3324
func rationalizeUpdateError(prime primeable, rerr *error) {
3425
if *rerr == nil {
3526
return
3627
}
3728

3829
var artifactCachedBuildErr *runtime.ArtifactCachedBuildFailed
3930
var artifactBuildErr *runtime.ArtifactBuildError
40-
var runtimeInUseErr *RuntimeInUseError
4131

4232
switch {
4333
// Artifact cached build errors
@@ -60,17 +50,6 @@ func rationalizeUpdateError(prime primeable, rerr *error) {
6050
errs.SetInput(),
6151
)
6252

63-
// Runtime in use
64-
case errors.As(*rerr, &runtimeInUseErr):
65-
list := []string{}
66-
for _, proc := range runtimeInUseErr.Processes {
67-
list = append(list, fmt.Sprintf(" - %s (process: %d)", proc.Exe, proc.Pid))
68-
}
69-
*rerr = errs.WrapUserFacing(*rerr,
70-
locale.Tr("runtime_setup_in_use_err", strings.Join(list, "\n")),
71-
errs.SetInput(),
72-
)
73-
7453
// Headless
7554
case errors.Is(*rerr, rationalize.ErrHeadless):
7655
*rerr = errs.WrapUserFacing(*rerr,

internal/runbits/runtime/runtime.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package runtime_runbit
22

33
import (
4+
"fmt"
45
"net/url"
56
"os"
7+
"strings"
68

79
anaConsts "github.com/ActiveState/cli/internal/analytics/constants"
810
"github.com/ActiveState/cli/internal/analytics/dimensions"
@@ -236,7 +238,11 @@ func Update(
236238
defer cancel()
237239
if procs, err := prime.SvcModel().GetProcessesInUse(ctx, rt.Env(false).ExecutorsPath); err == nil {
238240
if len(procs) > 0 {
239-
return nil, &RuntimeInUseError{procs}
241+
list := []string{}
242+
for _, proc := range procs {
243+
list = append(list, fmt.Sprintf(" - %s (process: %d)", proc.Exe, proc.Pid))
244+
}
245+
prime.Output().Notice(locale.Tr("runtime_setup_in_use_warning", strings.Join(list, "\n")))
240246
}
241247
} else {
242248
multilog.Error("Unable to determine if runtime is in use: %v", errs.JoinMessage(err))

test/integration/runtime_int_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func (suite *RuntimeIntegrationTestSuite) TestInterruptSetup() {
113113
}
114114

115115
func (suite *RuntimeIntegrationTestSuite) TestInUse() {
116+
if runtime.GOOS == "windows" {
117+
// https://activestatef.atlassian.net/browse/DX-2926
118+
suite.T().Skip("interrupting on windows is currently broken when ran via CI")
119+
}
116120
if runtime.GOOS == "darwin" {
117121
return // gopsutil errors on later versions of macOS (DX-2723)
118122
}
@@ -128,10 +132,9 @@ func (suite *RuntimeIntegrationTestSuite) TestInUse() {
128132
time.Sleep(1 * time.Second) // allow time for perl to start up
129133

130134
cp2 := ts.Spawn("install", "DateTime")
131-
cp2.Expect("currently in use", e2e.RuntimeSourcingTimeoutOpt)
135+
cp2.Expect("the runtime for this project is in use", e2e.RuntimeSourcingTimeoutOpt)
132136
cp2.Expect("perl")
133-
cp2.ExpectNotExitCode(0)
134-
ts.IgnoreLogErrors()
137+
cp2.ExpectExitCode(0)
135138

136139
cp.SendCtrlC()
137140
cp.SendLine("exit")

0 commit comments

Comments
 (0)