Skip to content

Commit 1877431

Browse files
Return exit code 0 when a core is already up to date (#2207)
* fix wrong type assertion * use feedback.Fatal otherwise it won't flush the stdout as json format * use feedback.PrintResult instead of using fatal * use errors.As in case in the future the err coming from PlatformUpgrade might be wrapped errors.As search through all the wrapped error for our target type, in case it finds it then it popolate that struct but more important we can use it as a type assertion even if is nested through many errors
1 parent d5fd94c commit 1877431

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

Diff for: internal/cli/core/upgrade.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool) {
110110
response, err := core.PlatformUpgrade(context.Background(), r, feedback.ProgressBar(), feedback.TaskProgress())
111111
warningMissingIndex(response)
112112
if err != nil {
113-
if errors.Is(err, &arduino.PlatformAlreadyAtTheLatestVersionError{}) {
114-
feedback.Print(err.Error())
113+
var alreadyAtLatestVersionErr *arduino.PlatformAlreadyAtTheLatestVersionError
114+
if errors.As(err, &alreadyAtLatestVersionErr) {
115+
feedback.Warning(err.Error())
115116
continue
116117
}
117118

@@ -122,4 +123,19 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool) {
122123
if hasBadArguments {
123124
feedback.Fatal(tr("Some upgrades failed, please check the output for details."), feedback.ErrBadArgument)
124125
}
126+
127+
feedback.PrintResult(&platformUpgradeResult{})
128+
}
129+
130+
// This is needed so we can print warning messages in case users use --format json
131+
type platformUpgradeResult struct{}
132+
133+
// Data implements feedback.Result.
134+
func (r *platformUpgradeResult) Data() interface{} {
135+
return r
136+
}
137+
138+
// String implements feedback.Result.
139+
func (r *platformUpgradeResult) String() string {
140+
return ""
125141
}

Diff for: internal/integrationtest/core/core_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1041,16 +1041,16 @@ func TestCoreUpgradeWarningWithPackageInstalledButNotIndexed(t *testing.T) {
10411041
_, _, err = cli.Run("core", "install", "test:[email protected]", "--additional-urls="+url)
10421042
require.NoError(t, err)
10431043
//upgrade without index fires a warning
1044-
_, jsonStderr, _ := cli.Run("core", "upgrade", "test:x86", "--format", "json")
1045-
requirejson.Query(t, jsonStderr, ".warnings[]", `"missing package index for test:x86, future updates cannot be guaranteed"`)
1044+
jsonStdout, _, _ := cli.Run("core", "upgrade", "test:x86", "--format", "json")
1045+
requirejson.Query(t, jsonStdout, ".warnings[]", `"missing package index for test:x86, future updates cannot be guaranteed"`)
10461046
})
10471047

10481048
// removing installed.json
10491049
installedJson := cli.DataDir().Join("packages", "test", "hardware", "x86", "1.0.0", "installed.json")
10501050
require.NoError(t, os.Remove(installedJson.String()))
10511051

10521052
t.Run("missing both installed.json and additional-urls", func(t *testing.T) {
1053-
_, jsonStderr, _ := cli.Run("core", "upgrade", "test:x86", "--format", "json")
1054-
requirejson.Query(t, jsonStderr, ".warnings[]", `"missing package index for test:x86, future updates cannot be guaranteed"`)
1053+
jsonStdout, _, _ := cli.Run("core", "upgrade", "test:x86", "--format", "json")
1054+
requirejson.Query(t, jsonStdout, ".warnings[]", `"missing package index for test:x86, future updates cannot be guaranteed"`)
10551055
})
10561056
}

0 commit comments

Comments
 (0)