Skip to content

Commit

Permalink
Clean up error logs.
Browse files Browse the repository at this point in the history
Use %v for errors, tidy some messages, make error messages start lowe-case
(as per go guidelines).  Just accumulated nits.
  • Loading branch information
thockin committed Nov 21, 2014
1 parent c688bd4 commit ea96071
Show file tree
Hide file tree
Showing 53 changed files with 163 additions and 163 deletions.
6 changes: 3 additions & 3 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,16 @@ func podExists(c *client.Client, podNamespace string, podID string) wait.Conditi
func runReplicationControllerTest(c *client.Client) {
data, err := ioutil.ReadFile("api/examples/controller.json")
if err != nil {
glog.Fatalf("Unexpected error: %#v", err)
glog.Fatalf("Unexpected error: %v", err)
}
var controller api.ReplicationController
if err := api.Scheme.DecodeInto(data, &controller); err != nil {
glog.Fatalf("Unexpected error: %#v", err)
glog.Fatalf("Unexpected error: %v", err)
}

glog.Infof("Creating replication controllers")
if _, err := c.ReplicationControllers(api.NamespaceDefault).Create(&controller); err != nil {
glog.Fatalf("Unexpected error: %#v", err)
glog.Fatalf("Unexpected error: %v", err)
}
glog.Infof("Done creating replication controllers")

Expand Down
10 changes: 5 additions & 5 deletions contrib/enscope/enscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func enscope(parent string, spec EnscopeSpec, in interface{}) (out interface{},

func ReadConfigData(location string) ([]byte, error) {
if len(location) == 0 {
return nil, fmt.Errorf("Location given but empty")
return nil, fmt.Errorf("location given but empty")
}

if location == "-" {
Expand All @@ -172,21 +172,21 @@ func readConfigDataFromLocation(location string) ([]byte, error) {
if strings.Index(location, "http://") == 0 || strings.Index(location, "https://") == 0 {
resp, err := http.Get(location)
if err != nil {
return nil, fmt.Errorf("Unable to access URL %s: %v\n", location, err)
return nil, fmt.Errorf("unable to access URL %s: %v\n", location, err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Unable to read URL, server reported %d %s", resp.StatusCode, resp.Status)
return nil, fmt.Errorf("unable to read URL, server reported %d %s", resp.StatusCode, resp.Status)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Unable to read URL %s: %v\n", location, err)
return nil, fmt.Errorf("unable to read URL %s: %v\n", location, err)
}
return data, nil
} else {
data, err := ioutil.ReadFile(location)
if err != nil {
return nil, fmt.Errorf("Unable to read %s: %v\n", location, err)
return nil, fmt.Errorf("unable to read %s: %v\n", location, err)
}
return data, nil
}
Expand Down
12 changes: 6 additions & 6 deletions contrib/simplegen/simplegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func portsFromString(spec string) (servicePort int, containerPort int, err error
pieces := strings.Split(spec, ":")
if len(pieces) != 2 {
glog.Infof("Bad port spec: %s", spec)
return 0, 0, fmt.Errorf("Bad port spec: %s", spec)
return 0, 0, fmt.Errorf("bad port spec: %s", spec)
}
servicePort, err = strconv.Atoi(pieces[0])
if err != nil {
Expand Down Expand Up @@ -207,7 +207,7 @@ func portsFromString(spec string) (servicePort int, containerPort int, err error

func ReadConfigData(location string) ([]byte, error) {
if len(location) == 0 {
return nil, fmt.Errorf("Location given but empty")
return nil, fmt.Errorf("location given but empty")
}

if location == "-" {
Expand All @@ -233,21 +233,21 @@ func readConfigDataFromLocation(location string) ([]byte, error) {
if strings.Index(location, "http://") == 0 || strings.Index(location, "https://") == 0 {
resp, err := http.Get(location)
if err != nil {
return nil, fmt.Errorf("Unable to access URL %s: %v\n", location, err)
return nil, fmt.Errorf("unable to access URL %s: %v\n", location, err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Unable to read URL, server reported %d %s", resp.StatusCode, resp.Status)
return nil, fmt.Errorf("unable to read URL, server reported %d %s", resp.StatusCode, resp.Status)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Unable to read URL %s: %v\n", location, err)
return nil, fmt.Errorf("unable to read URL %s: %v\n", location, err)
}
return data, nil
} else {
data, err := ioutil.ReadFile(location)
if err != nil {
return nil, fmt.Errorf("Unable to read %s: %v\n", location, err)
return nil, fmt.Errorf("unable to read %s: %v\n", location, err)
}
return data, nil
}
Expand Down
12 changes: 6 additions & 6 deletions contrib/srvexpand/srvexpand.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func portsFromString(spec string) (servicePort int, containerPort int, err error
pieces := strings.Split(spec, ":")
if len(pieces) != 2 {
glog.Infof("Bad port spec: %s", spec)
return 0, 0, fmt.Errorf("Bad port spec: %s", spec)
return 0, 0, fmt.Errorf("bad port spec: %s", spec)
}
servicePort, err = strconv.Atoi(pieces[0])
if err != nil {
Expand Down Expand Up @@ -266,7 +266,7 @@ func portsFromString(spec string) (servicePort int, containerPort int, err error

func ReadConfigData(location string) ([]byte, error) {
if len(location) == 0 {
return nil, fmt.Errorf("Location given but empty")
return nil, fmt.Errorf("location given but empty")
}

if location == "-" {
Expand All @@ -292,21 +292,21 @@ func readConfigDataFromLocation(location string) ([]byte, error) {
if strings.Index(location, "http://") == 0 || strings.Index(location, "https://") == 0 {
resp, err := http.Get(location)
if err != nil {
return nil, fmt.Errorf("Unable to access URL %s: %v\n", location, err)
return nil, fmt.Errorf("unable to access URL %s: %v\n", location, err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Unable to read URL, server reported %d %s", resp.StatusCode, resp.Status)
return nil, fmt.Errorf("unable to read URL, server reported %d %s", resp.StatusCode, resp.Status)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Unable to read URL %s: %v\n", location, err)
return nil, fmt.Errorf("unable to read URL %s: %v\n", location, err)
}
return data, nil
} else {
data, err := ioutil.ReadFile(location)
if err != nil {
return nil, fmt.Errorf("Unable to read %s: %v\n", location, err)
return nil, fmt.Errorf("unable to read %s: %v\n", location, err)
}
return data, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func NewConflict(kind, name string, err error) error {
Kind: kind,
ID: name,
},
Message: fmt.Sprintf("%s %q cannot be updated: %s", kind, name, err),
Message: fmt.Sprintf("%s %q cannot be updated: %v", kind, name, err),
}}
}

Expand All @@ -124,7 +124,7 @@ func NewInvalid(kind, name string, errs ValidationErrorList) error {
ID: name,
Causes: causes,
},
Message: fmt.Sprintf("%s %q is invalid: %s", kind, name, errs.ToError()),
Message: fmt.Sprintf("%s %q is invalid: %v", kind, name, errs.ToError()),
}}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (a genericAccessor) SetSelfLink(selfLink string) {
func fieldPtr(v reflect.Value, fieldName string, dest interface{}) error {
field := v.FieldByName(fieldName)
if !field.IsValid() {
return fmt.Errorf("Couldn't find %v field in %#v", fieldName, v.Interface())
return fmt.Errorf("couldn't find %v field in %#v", fieldName, v.Interface())
}
v, err := conversion.EnforcePtr(dest)
if err != nil {
Expand All @@ -309,7 +309,7 @@ func fieldPtr(v reflect.Value, fieldName string, dest interface{}) error {
v.Set(field.Convert(v.Type()))
return nil
}
return fmt.Errorf("Couldn't assign/convert %v to %v", field.Type(), v.Type())
return fmt.Errorf("couldn't assign/convert %v to %v", field.Type(), v.Type())
}

// extractFromTypeMeta extracts pointers to version and kind fields from an object
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func ValidateService(service *api.Service, lister ServiceLister, ctx api.Context
if services.Items[i].Name != service.Name &&
services.Items[i].Spec.CreateExternalLoadBalancer &&
services.Items[i].Spec.Port == service.Spec.Port {
allErrs = append(allErrs, errs.NewConflict("service", service.Name, fmt.Errorf("Port: %d is already in use", service.Spec.Port)))
allErrs = append(allErrs, errs.NewConflict("service", service.Name, fmt.Errorf("port: %d is already in use", service.Spec.Port)))
break
}
}
Expand Down Expand Up @@ -548,7 +548,7 @@ func ValidateMinionUpdate(oldMinion *api.Minion, minion *api.Minion) errs.Valida
oldMinion.Labels = minion.Labels
oldMinion.ObjectMeta.Labels = minion.ObjectMeta.Labels
if !reflect.DeepEqual(oldMinion, minion) {
allErrs = append(allErrs, fmt.Errorf("Update contains more than labels changes"))
allErrs = append(allErrs, fmt.Errorf("update contains more than labels changes"))
}
return allErrs
}
2 changes: 1 addition & 1 deletion pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ func TestValidateService(t *testing.T) {
registry.List = tc.existing
errs := ValidateService(&tc.svc, registry, api.NewDefaultContext())
if len(errs) != tc.numErrs {
t.Errorf("Unexpected error list for case %q: %+v", tc.name, errs)
t.Errorf("Unexpected error list for case %q: %v", tc.name, errs.ToError())
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func parseTimeout(str string) time.Duration {
if err == nil {
return timeout
}
glog.Errorf("Failed to parse: %#v '%s'", err, str)
glog.Errorf("Failed to parse %q: %v", str, err)
}
return 30 * time.Second
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *Client) ServerVersion() (*version.Info, error) {
var info version.Info
err = json.Unmarshal(body, &info)
if err != nil {
return nil, fmt.Errorf("Got '%s': %v", string(body), err)
return nil, fmt.Errorf("got '%s': %v", string(body), err)
}
return &info, nil
}
Expand All @@ -100,7 +100,7 @@ func (c *Client) ServerAPIVersions() (*api.APIVersions, error) {
var v api.APIVersions
err = json.Unmarshal(body, &v)
if err != nil {
return nil, fmt.Errorf("Got '%s': %v", string(body), err)
return nil, fmt.Errorf("got '%s': %v", string(body), err)
}
return &v, nil
}
4 changes: 2 additions & 2 deletions pkg/client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (r *Request) Body(obj interface{}) *Request {
}
r.body = bytes.NewBuffer(data)
default:
r.err = fmt.Errorf("Unknown type used for body: %#v", obj)
r.err = fmt.Errorf("unknown type used for body: %#v", obj)
}
return r
}
Expand Down Expand Up @@ -305,7 +305,7 @@ func (r *Request) Watch() (watch.Interface, error) {
if resp.Body != nil {
body, _ = ioutil.ReadAll(resp.Body)
}
return nil, fmt.Errorf("For request '%v', got status: %v\nbody: %v", req.URL, resp.StatusCode, string(body))
return nil, fmt.Errorf("for request '%v', got status: %v\nbody: %v", req.URL, resp.StatusCode, string(body))
}
return watch.NewStreamWatcher(watchjson.NewDecoder(resp.Body, r.codec)), nil
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/cloudprovider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func getAuth() (auth aws.Auth, err error) {
// readAWSCloudConfig reads an instance of AWSCloudConfig from config reader.
func readAWSCloudConfig(config io.Reader) (*AWSCloudConfig, error) {
if config == nil {
return nil, fmt.Errorf("No AWS cloud provider config file given")
return nil, fmt.Errorf("no AWS cloud provider config file given")
}

var cfg AWSCloudConfig
Expand All @@ -71,7 +71,7 @@ func readAWSCloudConfig(config io.Reader) (*AWSCloudConfig, error) {
}

if cfg.Global.Region == "" {
return nil, fmt.Errorf("No region specified in configuration file")
return nil, fmt.Errorf("no region specified in configuration file")
}

return &cfg, nil
Expand All @@ -81,7 +81,7 @@ func readAWSCloudConfig(config io.Reader) (*AWSCloudConfig, error) {
func newAWSCloud(config io.Reader, authFunc AuthFunc) (*AWSCloud, error) {
cfg, err := readAWSCloudConfig(config)
if err != nil {
return nil, fmt.Errorf("Unable to read AWS cloud provider config file: %s", err)
return nil, fmt.Errorf("unable to read AWS cloud provider config file: %v", err)
}

auth, err := authFunc()
Expand All @@ -91,7 +91,7 @@ func newAWSCloud(config io.Reader, authFunc AuthFunc) (*AWSCloud, error) {

region, ok := aws.Regions[cfg.Global.Region]
if !ok {
return nil, fmt.Errorf("Not a valid AWS region: %s", cfg.Global.Region)
return nil, fmt.Errorf("not a valid AWS region: %s", cfg.Global.Region)
}

ec2 := ec2.New(auth, region)
Expand Down Expand Up @@ -130,22 +130,22 @@ func (aws *AWSCloud) IPAddress(name string) (net.IP, error) {
return nil, err
}
if len(resp.Reservations) == 0 {
return nil, fmt.Errorf("No reservations found for host: %s", name)
return nil, fmt.Errorf("no reservations found for host: %s", name)
}
if len(resp.Reservations) > 1 {
return nil, fmt.Errorf("Multiple reservations found for host: %s", name)
return nil, fmt.Errorf("multiple reservations found for host: %s", name)
}
if len(resp.Reservations[0].Instances) == 0 {
return nil, fmt.Errorf("No instances found for host: %s", name)
return nil, fmt.Errorf("no instances found for host: %s", name)
}
if len(resp.Reservations[0].Instances) > 1 {
return nil, fmt.Errorf("Multiple instances found for host: %s", name)
return nil, fmt.Errorf("multiple instances found for host: %s", name)
}

ipAddress := resp.Reservations[0].Instances[0].PrivateIpAddress
ip := net.ParseIP(ipAddress)
if ip == nil {
return nil, fmt.Errorf("Invalid network IP: %s", ipAddress)
return nil, fmt.Errorf("invalid network IP: %s", ipAddress)
}
return ip, nil
}
Expand All @@ -157,7 +157,7 @@ func (aws *AWSCloud) getInstancesByRegex(regex string) ([]string, error) {
return []string{}, err
}
if resp == nil {
return []string{}, fmt.Errorf("No InstanceResp returned")
return []string{}, fmt.Errorf("no InstanceResp returned")
}

re, err := regexp.Compile(regex)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cloudprovider/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func getProjectAndZone() (string, string, error) {
}
parts := strings.Split(result, "/")
if len(parts) != 4 {
return "", "", fmt.Errorf("Unexpected response: %s", result)
return "", "", fmt.Errorf("unexpected response: %s", result)
}
return parts[1], parts[3], nil
}
Expand All @@ -91,7 +91,7 @@ func getInstanceID() (string, error) {
}
parts := strings.Split(result, ".")
if len(parts) == 0 {
return "", fmt.Errorf("Unexpected response: %s", result)
return "", fmt.Errorf("unexpected response: %s", result)
}
return parts[0], nil
}
Expand Down Expand Up @@ -266,7 +266,7 @@ func (gce *GCECloud) IPAddress(instance string) (net.IP, error) {
}
ip := net.ParseIP(res.NetworkInterfaces[0].AccessConfigs[0].NatIP)
if ip == nil {
return nil, fmt.Errorf("Invalid network IP: %s", res.NetworkInterfaces[0].AccessConfigs[0].NatIP)
return nil, fmt.Errorf("invalid network IP: %s", res.NetworkInterfaces[0].AccessConfigs[0].NatIP)
}
return ip, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (cfg Config) toAuthOptions() gophercloud.AuthOptions {

func readConfig(config io.Reader) (Config, error) {
if config == nil {
err := fmt.Errorf("No OpenStack cloud provider config file given")
err := fmt.Errorf("no OpenStack cloud provider config file given")
return Config{}, err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func InitCloudProvider(name string, configFilePath string) Interface {

cloud, err := GetCloudProvider(name, config)
if err != nil {
glog.Fatalf("Couldn't init cloud provider %q: %#v", name, err)
glog.Fatalf("Couldn't init cloud provider %q: %v", name, err)
}
if cloud == nil {
glog.Fatalf("Unknown cloud provider: %s", name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/vagrant/vagrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (v *VagrantCloud) IPAddress(instance string) (net.IP, error) {
return net.ParseIP(minion.IP), nil
}
}
return nil, fmt.Errorf("Unable to find IP address for instance: %s", instance)
return nil, fmt.Errorf("unable to find IP address for instance: %s", instance)
}

// saltMinionsByRole filters a list of minions that have a matching role.
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/replication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (rm *ReplicationManager) synchronize() {
glog.V(4).Infof("periodic sync of %v", controllers[ix].Name)
err := rm.syncHandler(controllers[ix])
if err != nil {
glog.Errorf("Error synchronizing: %#v", err)
glog.Errorf("Error synchronizing: %v", err)
}
}(ix)
}
Expand Down
Loading

0 comments on commit ea96071

Please sign in to comment.