Skip to content

Commit

Permalink
Fix trailing newlines when printing errors. (#1270)
Browse files Browse the repository at this point in the history
This changes fmt.Printf to clog.Printf since the former does not produce a trailing newline.
  • Loading branch information
porridge committed Jan 16, 2020
1 parent b53581a commit 99bd696
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 14 deletions.
3 changes: 2 additions & 1 deletion pkg/engine/task/podexec/pod_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -196,7 +197,7 @@ func untarFile(fs afero.Fs, r io.Reader, fileName string) error {
}

default:
fmt.Printf("skipping %s because it is not a regular file or a directory", header.Name)
log.Printf("skipping %s because it is not a regular file or a directory", header.Name)
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/kudoctl/cmd/plan/plan_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"
"github.com/xlab/treeprint"

"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
"github.com/kudobuilder/kudo/pkg/kudoctl/env"
)

Expand Down Expand Up @@ -41,15 +42,15 @@ func planHistory(options *Options, settings *env.Settings) error {

kc, err := env.GetClient(settings)
if err != nil {
fmt.Printf("Unable to create kudo client to talk to kubernetes API server %v", err)
clog.Printf("Unable to create KUDO client to talk to kubernetes API server: %v", err)
return err
}
instance, err := kc.GetInstance(options.Instance, namespace)
if err != nil {
return err
}
if instance == nil {
return fmt.Errorf("instance %s/%s does not exist", namespace, options.Instance)
return clog.Errorf("instance %s/%s does not exist", namespace, options.Instance)
}

tree := treeprint.New()
Expand Down
3 changes: 2 additions & 1 deletion pkg/kudoctl/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"

"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
"github.com/kudobuilder/kudo/pkg/kudoctl/cmd/install"
"github.com/kudobuilder/kudo/pkg/kudoctl/env"
"github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo"
Expand Down Expand Up @@ -99,6 +100,6 @@ func update(instanceToUpdate string, kc *kudo.Client, options *updateOptions, se
if err != nil {
return fmt.Errorf("updating instance %s %w", instanceToUpdate, err)
}
fmt.Printf("Instance %s was updated.", instanceToUpdate)
clog.Printf("Instance %s was updated.", instanceToUpdate)
return nil
}
5 changes: 3 additions & 2 deletions pkg/kudoctl/http/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"strings"

"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
"github.com/kudobuilder/kudo/pkg/version"
)

Expand Down Expand Up @@ -37,11 +38,11 @@ func (c *Client) Get(href string) (*bytes.Buffer, error) {

_, err = io.Copy(buf, resp.Body)
if err != nil {
fmt.Printf("Error when copying response buffer %s", err)
clog.Printf("Error when copying response buffer %s", err)
}
err = resp.Body.Close()
if err != nil {
fmt.Printf("Error when closing the response body %s", err)
clog.Printf("Error when closing the response body %s", err)
}
return buf, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/kudoctl/packages/reader/reader_tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/spf13/afero"

"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
"github.com/kudobuilder/kudo/pkg/kudoctl/packages"
)

Expand Down Expand Up @@ -47,7 +48,7 @@ func ParseTgz(r io.Reader) (*packages.Files, error) {
defer func() {
err := gzr.Close()
if err != nil {
fmt.Printf("Error when closing gzip reader: %s", err)
clog.Printf("Error when closing gzip reader: %s", err)
}
}()

Expand Down
3 changes: 2 additions & 1 deletion pkg/kudoctl/packages/writer/writer_tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/spf13/afero"

"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
"github.com/kudobuilder/kudo/pkg/kudoctl/files"
"github.com/kudobuilder/kudo/pkg/kudoctl/packages"
"github.com/kudobuilder/kudo/pkg/kudoctl/packages/reader"
Expand Down Expand Up @@ -69,7 +70,7 @@ func TgzDir(fs afero.Fs, path string, w io.Writer) (err error) {
// create a new dir/file header
header, err := tar.FileInfoHeader(fi, fi.Name())
if err != nil {
fmt.Printf("Error creating tar header for: %v", fi.Name())
clog.Printf("Error creating tar header for: %v", fi.Name())
return err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/kudoctl/util/repo/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package repo

import (
"bytes"
"fmt"
"io"
"io/ioutil"

"github.com/spf13/afero"

"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
"github.com/kudobuilder/kudo/pkg/kudoctl/files"
"github.com/kudobuilder/kudo/pkg/kudoctl/packages"
"github.com/kudobuilder/kudo/pkg/kudoctl/packages/reader"
Expand All @@ -30,7 +30,7 @@ func mapPaths(fs afero.Fs, paths []string, f func(afero.Fs, string) (*PackageFil
for _, path := range paths {
op, err := f(fs, path)
if err != nil {
fmt.Printf("WARNING: operator: %v is invalid", path)
clog.Printf("WARNING: operator: %v is invalid", path)
continue
}
ops = append(ops, op)
Expand Down
3 changes: 2 additions & 1 deletion pkg/kudoctl/util/repo/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spf13/afero"
"sigs.k8s.io/yaml"

"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
"github.com/kudobuilder/kudo/pkg/kudoctl/packages"
)

Expand Down Expand Up @@ -109,7 +110,7 @@ func (i IndexFile) Write(w io.Writer) error {
}
_, err = w.Write(b)
if err != nil {
fmt.Printf("err: %v", err)
clog.Printf("Error writing index file: %v", err)
}
return err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/test/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/kudobuilder/kudo/pkg/controller/instance"
"github.com/kudobuilder/kudo/pkg/controller/operator"
"github.com/kudobuilder/kudo/pkg/controller/operatorversion"
"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
testutils "github.com/kudobuilder/kudo/pkg/test/utils"
)

Expand Down Expand Up @@ -283,7 +284,7 @@ func (h *Harness) RunKUDO() error {
h.managerStopCh = make(chan struct{})
go func(stopCh chan struct{}) {
if err := mgr.Start(stopCh); err != nil {
fmt.Printf("failed to start the manager")
clog.Printf("failed to start the manager: %v", err)
os.Exit(-1)
}
}(h.managerStopCh)
Expand Down
5 changes: 3 additions & 2 deletions pkg/test/utils/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (

"github.com/kudobuilder/kudo/pkg/apis"
harness "github.com/kudobuilder/kudo/pkg/apis/testharness/v1beta1"
"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
)

// ensure that we only add to the scheme once.
Expand Down Expand Up @@ -260,11 +261,11 @@ func (r *RetryStatusWriter) Patch(ctx context.Context, obj runtime.Object, patch
func Scheme() *runtime.Scheme {
schemeLock.Do(func() {
if err := apis.AddToScheme(scheme.Scheme); err != nil {
fmt.Printf("failed to add API resources to the scheme: %v", err)
clog.Printf("failed to add API resources to the scheme: %v", err)
os.Exit(-1)
}
if err := apiextensions.AddToScheme(scheme.Scheme); err != nil {
fmt.Printf("failed to add API extension resources to the scheme: %v", err)
clog.Printf("failed to add API extension resources to the scheme: %v", err)
os.Exit(-1)
}
})
Expand Down

0 comments on commit 99bd696

Please sign in to comment.