Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not print unsupported mixin command errors #2488

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/testmixin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func main() {
// This is a mixin that helps us test out our schema command
fmt.Println(schema)
case "lint":
fmt.Println("[]")
// The test mixin does not implement lint
fmt.Fprintln(os.Stderr, `unknown command "lint" for "testmixin"`)
os.Exit(1)
case "build":
fmt.Println("# testmixin")
case "run":
Expand Down
6 changes: 5 additions & 1 deletion pkg/pkgmgmt/client/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ func (r *Runner) Run(ctx context.Context, commandOpts pkgmgmt.CommandOptions) er
err = cmd.Wait()
if err != nil {
// Include stderr in the error, otherwise it just includes the exit code
return span.Error(fmt.Errorf("package command failed %s\n%s", prettyCmd, cmdStderr))
err = fmt.Errorf("package command failed %s\n%s", prettyCmd, cmdStderr)
// Do not flag this as an error in the logs because we often call mixins to see if they support a command
// and if they don't it's not an error, e.g. not all mixins support lint or schema
span.Debugf(err.Error())
return err
}

return nil
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/lint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//go:build integration

package integration

import (
"path/filepath"
"testing"

"get.porter.sh/porter/tests/tester"
"github.com/carolynvs/magex/shx"
"github.com/stretchr/testify/require"
)

func TestLint(t *testing.T) {
test, err := tester.NewTest(t)
defer test.Close()
require.NoError(t, err, "test setup failed")

// When a mixin doesn't support lint, we should not print that to the console unless we are in debug mode
_, output, _ := test.RunPorterWith(func(cmd *shx.PreparedCommand) {
cmd.Args("lint")
// mybuns uses the testmixin which doesn't support lint
cmd.In(filepath.Join(test.RepoRoot, "tests/testdata/mybuns"))
// change verbosity to debug so that we see the error
cmd.Env("PORTER_VERBOSITY=debug")
})
require.Contains(t, output, "unknown command", "an unsupported mixin command should print to the console in debug")

_, output, _ = test.RunPorterWith(func(cmd *shx.PreparedCommand) {
cmd.Args("lint")
// mybuns uses the testmixin which doesn't support lint
cmd.In(filepath.Join(test.RepoRoot, "tests/testdata/mybuns"))
// errors are printed at the debug level to bump it up to info
cmd.Env("PORTER_VERBOSITY=info")
})
require.NotContains(t, output, "unknown command", "an unsupported mixin command should not be printed to the console in info")

}