diff --git a/pkg/exec/builder/errors.go b/pkg/exec/builder/errors.go index 68aff8154..eade0c235 100644 --- a/pkg/exec/builder/errors.go +++ b/pkg/exec/builder/errors.go @@ -74,7 +74,7 @@ func (h IgnoreErrorHandler) HandleError(ctx context.Context, err ExitError, stdo for _, allowMatch := range h.Output.Regex { expression, regexErr := regexp.Compile(allowMatch) if regexErr != nil { - span.Error(fmt.Errorf("Could not ignore failed command because the Regex specified by the mixin step definition (%q) is invalid:%s", allowMatch, regexErr.Error())) + err := span.Error(fmt.Errorf("Could not ignore failed command because the Regex specified by the mixin step definition (%q) is invalid:%s", allowMatch, regexErr.Error())) return err } diff --git a/pkg/exec/version_test.go b/pkg/exec/version_test.go index 4456be08c..b4136ec25 100644 --- a/pkg/exec/version_test.go +++ b/pkg/exec/version_test.go @@ -19,7 +19,8 @@ func TestPrintVersion(t *testing.T) { opts := version.Options{} err := opts.Validate() require.NoError(t, err) - m.PrintVersion(opts) + err = m.PrintVersion(opts) + require.NoError(t, err) gotOutput := m.TestConfig.TestContext.GetOutput() wantOutput := "exec v1.2.3 (abc123) by Porter Authors" @@ -38,7 +39,8 @@ func TestPrintJsonVersion(t *testing.T) { opts.RawFormat = string(printer.FormatJson) err := opts.Validate() require.NoError(t, err) - m.PrintVersion(opts) + err = m.PrintVersion(opts) + require.NoError(t, err) gotOutput := m.TestConfig.TestContext.GetOutput() wantOutput := `{ diff --git a/pkg/pkgmgmt/client/install.go b/pkg/pkgmgmt/client/install.go index 94304c0b4..8d6e28b6d 100644 --- a/pkg/pkgmgmt/client/install.go +++ b/pkg/pkgmgmt/client/install.go @@ -200,14 +200,18 @@ func (fs *FileSystem) downloadFile(ctx context.Context, url url.URL, destPath st return log.Error(fmt.Errorf("unable to check if directory exists %s: %w", parentDir, err)) } - cleanup := func() {} + cleanup := func() error { return nil } if !parentDirExists { err = fs.FileSystem.MkdirAll(parentDir, pkg.FileModeDirectory) if err != nil { return log.Error(fmt.Errorf("unable to create parent directory %s: %w", parentDir, err)) } - cleanup = func() { - fs.FileSystem.RemoveAll(parentDir) // If we can't download the file, don't leave traces of it + cleanup = func() error { + // If we can't download the file, don't leave traces of it + if err = fs.FileSystem.RemoveAll(parentDir); err != nil { + return err + } + return nil } } diff --git a/pkg/pkgmgmt/client/runner.go b/pkg/pkgmgmt/client/runner.go index eded5939a..e56f372d7 100644 --- a/pkg/pkgmgmt/client/runner.go +++ b/pkg/pkgmgmt/client/runner.go @@ -84,7 +84,9 @@ func (r *Runner) Run(ctx context.Context, commandOpts pkgmgmt.CommandOptions) er } go func() { defer stdin.Close() - io.WriteString(stdin, commandOpts.Input) + if _, err := io.WriteString(stdin, commandOpts.Input); err != nil { + span.Error(err) + } }() } diff --git a/pkg/pkgmgmt/feed/generate_test.go b/pkg/pkgmgmt/feed/generate_test.go index f5208e202..d78abe781 100644 --- a/pkg/pkgmgmt/feed/generate_test.go +++ b/pkg/pkgmgmt/feed/generate_test.go @@ -15,65 +15,183 @@ import ( ) func TestGenerate(t *testing.T) { + var err error ctx := context.Background() tc := portercontext.NewTestContext(t) tc.AddTestFile("testdata/atom-template.xml", "template.xml") - tc.FileSystem.Create("bin/v1.2.3/helm-darwin-amd64") - tc.FileSystem.Create("bin/v1.2.3/helm-darwin-arm64") - tc.FileSystem.Create("bin/v1.2.3/helm-linux-amd64") - tc.FileSystem.Create("bin/v1.2.3/helm-linux-arm64") - tc.FileSystem.Create("bin/v1.2.3/helm-windows-amd64.exe") - tc.FileSystem.Create("bin/v1.2.3/helm-windows-arm64.exe") + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-darwin-arm64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-linux-arm64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/helm-windows-arm64.exe") + if err != nil { + require.NoError(t, err) + } // Force the up3 timestamps to stay the same for each test run up3, _ := time.Parse("2006-Jan-02", "2013-Feb-03") - tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-amd64", up3, up3) - tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-arm64", up3, up3) - tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-amd64", up3, up3) - tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-arm64", up3, up3) - tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-amd64.exe", up3, up3) - tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-arm64.exe", up3, up3) + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-amd64", up3, up3) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-darwin-arm64", up3, up3) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-amd64", up3, up3) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-linux-arm64", up3, up3) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-amd64.exe", up3, up3) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/helm-windows-arm64.exe", up3, up3) + if err != nil { + require.NoError(t, err) + } - tc.FileSystem.Create("bin/v1.2.4/helm-darwin-amd64") - tc.FileSystem.Create("bin/v1.2.4/helm-linux-amd64") - tc.FileSystem.Create("bin/v1.2.4/helm-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/v1.2.4/helm-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.4/helm-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.4/helm-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } up4, _ := time.Parse("2006-Jan-02", "2013-Feb-04") - tc.FileSystem.Chtimes("bin/v1.2.4/helm-darwin-amd64", up4, up4) - tc.FileSystem.Chtimes("bin/v1.2.4/helm-linux-amd64", up4, up4) - tc.FileSystem.Chtimes("bin/v1.2.4/helm-windows-amd64.exe", up4, up4) + err = tc.FileSystem.Chtimes("bin/v1.2.4/helm-darwin-amd64", up4, up4) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.4/helm-linux-amd64", up4, up4) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.4/helm-windows-amd64.exe", up4, up4) + if err != nil { + require.NoError(t, err) + } - tc.FileSystem.Create("bin/v1.2.3/exec-darwin-amd64") - tc.FileSystem.Create("bin/v1.2.3/exec-linux-amd64") - tc.FileSystem.Create("bin/v1.2.3/exec-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/v1.2.3/exec-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/exec-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v1.2.3/exec-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } up2, _ := time.Parse("2006-Jan-02", "2013-Feb-02") - tc.FileSystem.Chtimes("bin/v1.2.3/exec-darwin-amd64", up2, up2) - tc.FileSystem.Chtimes("bin/v1.2.3/exec-linux-amd64", up2, up2) - tc.FileSystem.Chtimes("bin/v1.2.3/exec-windows-amd64.exe", up2, up2) + err = tc.FileSystem.Chtimes("bin/v1.2.3/exec-darwin-amd64", up2, up2) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/exec-linux-amd64", up2, up2) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/v1.2.3/exec-windows-amd64.exe", up2, up2) + if err != nil { + require.NoError(t, err) + } - tc.FileSystem.Create("bin/canary/exec-darwin-amd64") - tc.FileSystem.Create("bin/canary/exec-linux-amd64") - tc.FileSystem.Create("bin/canary/exec-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/canary/exec-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/canary/exec-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/canary/exec-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } up10, _ := time.Parse("2006-Jan-02", "2013-Feb-10") - tc.FileSystem.Chtimes("bin/canary/exec-darwin-amd64", up10, up10) - tc.FileSystem.Chtimes("bin/canary/exec-linux-amd64", up10, up10) - tc.FileSystem.Chtimes("bin/canary/exec-windows-amd64.exe", up10, up10) + err = tc.FileSystem.Chtimes("bin/canary/exec-darwin-amd64", up10, up10) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/canary/exec-linux-amd64", up10, up10) + if err != nil { + require.NoError(t, err) + } + err = tc.FileSystem.Chtimes("bin/canary/exec-windows-amd64.exe", up10, up10) + if err != nil { + require.NoError(t, err) + } // Create extraneous release directories that should be ignored - tc.FileSystem.Create("bin/v0.34.0-1-gda/helm-darwin-amd64") - tc.FileSystem.Create("bin/v0.34.0-2-g1234567/helm-linux-amd64") - tc.FileSystem.Create("bin/v0.34.0-3-g12345/helm-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/v0.34.0-1-gda/helm-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v0.34.0-2-g1234567/helm-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/v0.34.0-3-g12345/helm-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } - tc.FileSystem.Create("bin/latest/helm-darwin-amd64") - tc.FileSystem.Create("bin/latest/helm-linux-amd64") - tc.FileSystem.Create("bin/latest/helm-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/latest/helm-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/latest/helm-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/latest/helm-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } - tc.FileSystem.Create("bin/canary-v1/exec-darwin-amd64") - tc.FileSystem.Create("bin/canary-v1/exec-linux-amd64") - tc.FileSystem.Create("bin/canary-v1/exec-windows-amd64.exe") + _, err = tc.FileSystem.Create("bin/canary-v1/exec-darwin-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/canary-v1/exec-linux-amd64") + if err != nil { + require.NoError(t, err) + } + _, err = tc.FileSystem.Create("bin/canary-v1/exec-windows-amd64.exe") + if err != nil { + require.NoError(t, err) + } opts := GenerateOptions{ AtomFile: "atom.xml", @@ -81,7 +199,7 @@ func TestGenerate(t *testing.T) { TemplateFile: "template.xml", } f := NewMixinFeed(tc.Context) - err := f.Generate(ctx, opts) + err = f.Generate(ctx, opts) require.NoError(t, err) err = f.Save(opts) require.NoError(t, err) @@ -142,9 +260,19 @@ func TestGenerate_RegexMatch(t *testing.T) { porterCtx.AddTestFile("testdata/atom-template.xml", "template.xml") if tc.mixinName != "" { - porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-darwin-amd64", tc.mixinName)) - porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-linux-amd64", tc.mixinName)) - porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-windows-amd64.exe", tc.mixinName)) + var err error + _, err = porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-darwin-amd64", tc.mixinName)) + if err != nil { + require.NoError(t, err) + } + _, err = porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-linux-amd64", tc.mixinName)) + if err != nil { + require.NoError(t, err) + } + _, err = porterCtx.FileSystem.Create(fmt.Sprintf("bin/v1.2.3/%s-windows-amd64.exe", tc.mixinName)) + if err != nil { + require.NoError(t, err) + } } opts := GenerateOptions{ diff --git a/pkg/plugins/pluggable/connection.go b/pkg/plugins/pluggable/connection.go index 1aff49d40..95b061906 100644 --- a/pkg/plugins/pluggable/connection.go +++ b/pkg/plugins/pluggable/connection.go @@ -161,7 +161,7 @@ func (c *PluginConnection) Start(ctx context.Context, pluginCfg io.Reader) error pluginErr = ": plugin stderr was " + pluginErr } err = fmt.Errorf("could not connect to the %s plugin%s: %w", c.key, pluginErr, err) - span.Error(err) // Emit the error before trying to close the connection + err = span.Error(err) // Emit the error before trying to close the connection c.Close(ctx) return err } diff --git a/pkg/portercontext/context_test.go b/pkg/portercontext/context_test.go index f7b4e8516..4603349a6 100644 --- a/pkg/portercontext/context_test.go +++ b/pkg/portercontext/context_test.go @@ -44,7 +44,10 @@ func TestContext_LogToFile(t *testing.T) { _, log := c.StartRootSpan(context.Background(), t.Name()) log.Info("a thing happened") log.Warn("a weird thing happened") - log.Error(errors.New("a bad thing happened")) + //throwing away error here because it is a test + // we do not return it + _ = log.Error(errors.New("a bad thing happened")) + log.EndSpan() c.Close() diff --git a/workshop/porter-tf-aci/azure/app/main.go b/workshop/porter-tf-aci/azure/app/main.go index 6155ae490..fcb9aa052 100644 --- a/workshop/porter-tf-aci/azure/app/main.go +++ b/workshop/porter-tf-aci/azure/app/main.go @@ -13,7 +13,10 @@ func handle(w http.ResponseWriter, r *http.Request) { http.Error(w, "couldn't find MYSQL FQDN", http.StatusInternalServerError) } - w.Write([]byte(fmt.Sprintf("Hello, I'm a webserver that wants to connect to a MYSQL at %s", sqlFQDN))) + _, err := w.Write([]byte(fmt.Sprintf("Hello, I'm a webserver that wants to connect to a MYSQL at %s", sqlFQDN))) + if err != nil { + log.Fatal(err) + } } func main() {