Skip to content

Commit

Permalink
errors: Precede with colon
Browse files Browse the repository at this point in the history
Precede each `%w` formatter with a colon.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
  • Loading branch information
jrajahalme committed Apr 3, 2024
1 parent d20f15e commit fe46958
Show file tree
Hide file tree
Showing 23 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions bugtool/cmd/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ func save(c *BugtoolConfiguration, path string) error {

data, err := json.MarshalIndent(c, "", "\t")
if err != nil {
return fmt.Errorf("Cannot marshal config %w", err)
return fmt.Errorf("Cannot marshal config: %w", err)
}
err = os.WriteFile(path, data, 0644)
if err != nil {
return fmt.Errorf("Cannot write config %w", err)
return fmt.Errorf("Cannot write config: %w", err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/cmd/cni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (c *cniConfigManager) renderCNIConf() (cniConfig []byte, err error) {
func (c *cniConfigManager) mergeExistingCNIConfig(pluginConfig []byte) ([]byte, error) {
contents, err := c.findCNINetwork(c.config.CNIChainingTarget)
if err != nil {
return nil, fmt.Errorf("could not find existing CNI config for chaining %w", err)
return nil, fmt.Errorf("could not find existing CNI config for chaining: %w", err)
}

// Check to see if we're already inserted; otherwise we should append
Expand Down
2 changes: 1 addition & 1 deletion daemon/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (c *ConfigModifyEvent) configModify(params PatchConfigParams, resChan chan

om, err := option.Config.Opts.Library.ValidateConfigurationMap(cfgSpec.Options)
if err != nil {
msg := fmt.Errorf("Invalid configuration option %w", err)
msg := fmt.Errorf("Invalid configuration option: %w", err)
resChan <- api.Error(PatchConfigBadRequestCode, msg)
return
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/cmd/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ func (d *Daemon) allocateDatapathIPs(family types.NodeAddressingFamily, fromK8s,
result.PrimaryMAC, result.InterfaceNumber, option.Config.IPAM,
option.Config.EnableIPv4Masquerade)
if err != nil {
return nil, fmt.Errorf("failed to create router info %w", err)
return nil, fmt.Errorf("failed to create router info: %w", err)
}
if err = routingInfo.Configure(
result.IP,
d.mtuConfig.GetDeviceMTU(),
option.Config.EgressMultiHomeIPRuleCompat,
true,
); err != nil {
return nil, fmt.Errorf("failed to configure router IP rules and routes %w", err)
return nil, fmt.Errorf("failed to configure router IP rules and routes: %w", err)
}

node.SetRouterInfo(routingInfo)
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/gateway-api/gateway_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func isValidPemFormat(b []byte) bool {

func (r *gatewayReconciler) handleReconcileErrorWithStatus(ctx context.Context, reconcileErr error, original *gatewayv1.Gateway, modified *gatewayv1.Gateway) (ctrl.Result, error) {
if err := r.updateStatus(ctx, original, modified); err != nil {
return controllerruntime.Fail(fmt.Errorf("failed to update Gateway status while handling the reconcile error %w: %w", reconcileErr, err))
return controllerruntime.Fail(fmt.Errorf("failed to update Gateway status while handling the reconcile error: %w: %w", reconcileErr, err))
}

return controllerruntime.Fail(reconcileErr)
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/gateway-api/grpcroute_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (r *grpcRouteReconciler) updateStatus(ctx context.Context, original *gatewa

func (r *grpcRouteReconciler) handleReconcileErrorWithStatus(ctx context.Context, reconcileErr error, original *gatewayv1alpha2.GRPCRoute, modified *gatewayv1alpha2.GRPCRoute) (ctrl.Result, error) {
if err := r.updateStatus(ctx, original, modified); err != nil {
return controllerruntime.Fail(fmt.Errorf("failed to update GRPCRoute status while handling the reconcile error %w: %w", reconcileErr, err))
return controllerruntime.Fail(fmt.Errorf("failed to update GRPCRoute status while handling the reconcile error: %w: %w", reconcileErr, err))
}

return controllerruntime.Fail(reconcileErr)
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/gateway-api/httproute_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (r *httpRouteReconciler) updateStatus(ctx context.Context, original *gatewa

func (r *httpRouteReconciler) handleReconcileErrorWithStatus(ctx context.Context, reconcileErr error, original *gatewayv1.HTTPRoute, modified *gatewayv1.HTTPRoute) (ctrl.Result, error) {
if err := r.updateStatus(ctx, original, modified); err != nil {
return controllerruntime.Fail(fmt.Errorf("failed to update HTTPRoute status while handling the reconcile error %w: %w", reconcileErr, err))
return controllerruntime.Fail(fmt.Errorf("failed to update HTTPRoute status while handling the reconcile error: %w: %w", reconcileErr, err))
}

return controllerruntime.Fail(reconcileErr)
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/gateway-api/tlsroute_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (r *tlsRouteReconciler) updateStatus(ctx context.Context, original *gateway

func (r *tlsRouteReconciler) handleReconcileErrorWithStatus(ctx context.Context, reconcileErr error, original *gatewayv1alpha2.TLSRoute, modified *gatewayv1alpha2.TLSRoute) (ctrl.Result, error) {
if err := r.updateStatus(ctx, original, modified); err != nil {
return controllerruntime.Fail(fmt.Errorf("failed to update TLSRoute status while handling the reconcile error %w: %w", reconcileErr, err))
return controllerruntime.Fail(fmt.Errorf("failed to update TLSRoute status while handling the reconcile error: %w: %w", reconcileErr, err))
}

return controllerruntime.Fail(reconcileErr)
Expand Down
8 changes: 4 additions & 4 deletions pkg/alibabacloud/eni/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (n *Node) CreateInterface(ctx context.Context, allocation *ipam.AllocationA
if err != nil {
return 0,
unableToGetSecurityGroups,
fmt.Errorf("%s %w", errUnableToGetSecurityGroups, err)
fmt.Errorf("%s: %w", errUnableToGetSecurityGroups, err)
}

scopedLog = scopedLog.WithFields(logrus.Fields{
Expand All @@ -149,7 +149,7 @@ func (n *Node) CreateInterface(ctx context.Context, allocation *ipam.AllocationA
eniID, eni, err := n.manager.api.CreateNetworkInterface(ctx, toAllocate-1, bestSubnet.ID, securityGroupIDs,
utils.FillTagWithENIIndex(map[string]string{}, index))
if err != nil {
return 0, unableToCreateENI, fmt.Errorf("%s %w", errUnableToCreateENI, err)
return 0, unableToCreateENI, fmt.Errorf("%s: %w", errUnableToCreateENI, err)
}

scopedLog = scopedLog.WithField(fieldENIID, eniID)
Expand All @@ -165,15 +165,15 @@ func (n *Node) CreateInterface(ctx context.Context, allocation *ipam.AllocationA
if err2 != nil {
scopedLog.Errorf("Failed to release ENI after failure to attach, %s", err2.Error())
}
return 0, unableToAttachENI, fmt.Errorf("%s %w", errUnableToAttachENI, err)
return 0, unableToAttachENI, fmt.Errorf("%s: %w", errUnableToAttachENI, err)
}
_, err = n.manager.api.WaitENIAttached(ctx, eniID)
if err != nil {
err2 := n.manager.api.DeleteNetworkInterface(ctx, eniID)
if err2 != nil {
scopedLog.Errorf("Failed to release ENI after failure to attach, %s", err2.Error())
}
return 0, unableToAttachENI, fmt.Errorf("%s %w", errUnableToAttachENI, err)
return 0, unableToAttachENI, fmt.Errorf("%s: %w", errUnableToAttachENI, err)
}

n.enis[eniID] = *eni
Expand Down
4 changes: 2 additions & 2 deletions pkg/aws/eni/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func (n *Node) CreateInterface(ctx context.Context, allocation *ipam.AllocationA
if err != nil {
return 0,
unableToGetSecurityGroups,
fmt.Errorf("%s %w", errUnableToGetSecurityGroups, err)
fmt.Errorf("%s: %w", errUnableToGetSecurityGroups, err)
}

desc := "Cilium-CNI (" + n.node.InstanceID() + ")"
Expand Down Expand Up @@ -462,7 +462,7 @@ func (n *Node) CreateInterface(ctx context.Context, allocation *ipam.AllocationA
eniID, eni, err = n.manager.api.CreateNetworkInterface(ctx, int32(toAllocate), subnet.ID, desc, securityGroupIDs, false)
}
if err != nil {
return 0, unableToCreateENI, fmt.Errorf("%s %w", errUnableToCreateENI, err)
return 0, unableToCreateENI, fmt.Errorf("%s: %w", errUnableToCreateENI, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/bgpv1/api/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ToAgentGetRoutesRequest(params restapi.GetBgpRoutesParams) (*types.GetRoute
}
addr, err := netip.ParseAddr(*params.Neighbor)
if err != nil {
return nil, fmt.Errorf("invalid neighbor address %w", err)
return nil, fmt.Errorf("invalid neighbor address: %w", err)
}
ret.Neighbor = addr
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/bgpv1/test/gobgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (g *goBGP) waitForSessionState(ctx context.Context, expectedStates []string
}
}
case <-ctx.Done():
return fmt.Errorf("did not receive expected peering state %q, %w", expectedStates, ctx.Err())
return fmt.Errorf("did not receive expected peering state %q: %w", expectedStates, ctx.Err())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cgroups/manager/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ func getSystemdContainerPathCommon(subPaths []string, podId string, containerId
podIdStr := fmt.Sprintf("pod%s", podId)
if qos == v1.PodQOSGuaranteed {
if path, err = toSystemd(append(subPaths, podIdStr)); err != nil {
return "", fmt.Errorf("unable to construct cgroup path %w", err)
return "", fmt.Errorf("unable to construct cgroup path: %w", err)
}
} else {
qosStr := strings.ToLower(string(qos))
if path, err = toSystemd(append(subPaths, qosStr, podIdStr)); err != nil {
return "", fmt.Errorf("unable to construct cgroup path %w", err)
return "", fmt.Errorf("unable to construct cgroup path: %w", err)
}
}
// construct and append container sub path with container id
Expand Down
4 changes: 2 additions & 2 deletions pkg/datapath/linux/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,10 @@ func (n *linuxNodeHandler) nodeDelete(oldNode *nodeTypes.Node) error {
var errs error
if n.nodeConfig.EnableAutoDirectRouting && !n.enableEncapsulation(oldNode) {
if err := n.deleteDirectRoute(oldNode.IPv4AllocCIDR, oldIP4); err != nil {
errs = errors.Join(errs, fmt.Errorf("failed to remove old direct routing: deleting old routes %w", err))
errs = errors.Join(errs, fmt.Errorf("failed to remove old direct routing: deleting old routes: %w", err))
}
if err := n.deleteDirectRoute(oldNode.IPv6AllocCIDR, oldIP6); err != nil {
errs = errors.Join(errs, fmt.Errorf("failed to remove old direct routing: deleting old routes %w", err))
errs = errors.Join(errs, fmt.Errorf("failed to remove old direct routing: deleting old routes: %w", err))
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/hubble/exporter/config_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ func (c *configWatcher) readConfig() (*DynamicExportersConfig, uint64, error) {
config := &DynamicExportersConfig{}
yamlFile, err := os.ReadFile(c.configFilePath)
if err != nil {
return nil, 0, fmt.Errorf("cannot read file '%s' %w", c.configFilePath, err)
return nil, 0, fmt.Errorf("cannot read file '%s': %w", c.configFilePath, err)
}
if err := yaml.Unmarshal(yamlFile, config); err != nil {
return nil, 0, fmt.Errorf("cannot parse yaml %w", err)
return nil, 0, fmt.Errorf("cannot parse yaml: %w", err)
}

if err := validateConfig(config); err != nil {
return nil, 0, fmt.Errorf("invalid yaml config file %w", err)
return nil, 0, fmt.Errorf("invalid yaml config file: %w", err)
}

return config, calculateHash(yamlFile), nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/hubble/exporter/config_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ func TestInvalidConfigFile(t *testing.T) {
{
name: "duplicated name",
watcher: &configWatcher{configFilePath: "testdata/duplicate-names-flowlogs-config.yaml"},
expectedErrorMsg: "invalid yaml config file duplicated flowlog name test001",
expectedErrorMsg: "invalid yaml config file: duplicated flowlog name test001",
},
{
name: "duplicated path",
watcher: &configWatcher{configFilePath: "testdata/duplicate-paths-flowlogs-config.yaml"},
expectedErrorMsg: "invalid yaml config file duplicated flowlog path /var/log/network/flow-log/pa/test001.log",
expectedErrorMsg: "invalid yaml config file: duplicated flowlog path /var/log/network/flow-log/pa/test001.log",
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/ipam/allocator/clusterpool/clusterpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (a *AllocatorOperator) Init(ctx context.Context) error {

v4Allocators, err := cidralloc.NewCIDRSets(false, operatorOption.Config.ClusterPoolIPv4CIDR, operatorOption.Config.NodeCIDRMaskSizeIPv4)
if err != nil {
return fmt.Errorf("unable to initialize IPv4 allocator %w", err)
return fmt.Errorf("unable to initialize IPv4 allocator: %w", err)
}
a.v4CIDRSet = v4Allocators
} else if len(operatorOption.Config.ClusterPoolIPv4CIDR) != 0 {
Expand All @@ -53,7 +53,7 @@ func (a *AllocatorOperator) Init(ctx context.Context) error {

v6Allocators, err := cidralloc.NewCIDRSets(true, operatorOption.Config.ClusterPoolIPv6CIDR, operatorOption.Config.NodeCIDRMaskSizeIPv6)
if err != nil {
return fmt.Errorf("unable to initialize IPv6 allocator %w", err)
return fmt.Errorf("unable to initialize IPv6 allocator: %w", err)
}
a.v6CIDRSet = v6Allocators
} else if len(operatorOption.Config.ClusterPoolIPv6CIDR) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ipam/service/ipallocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (r *Range) Restore(net *net.IPNet, data []byte) error {
return fmt.Errorf("not a snapshottable allocator")
}
if err := snapshottable.Restore(net.String(), data); err != nil {
return fmt.Errorf("restoring snapshot encountered %w", err)
return fmt.Errorf("restoring snapshot encountered: %w", err)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mtu/detect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func autoDetect() (int, error) {
prevErr := err
routes, err = getRoute(externalProbeIPv6)
if err != nil {
return 0, fmt.Errorf("%w, %w", err, prevErr)
return 0, fmt.Errorf("%w: %w", err, prevErr)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/redirectpolicy/redirectpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func getSanitizedLRPConfig(name, namespace string, uid types.UID, spec v2.Cilium
for i, portInfo := range addrMatcher.ToPorts {
p, pName, proto, err := portInfo.SanitizePortInfo(checkNamedPort)
if err != nil {
return nil, fmt.Errorf("invalid address matcher port %w", err)
return nil, fmt.Errorf("invalid address matcher port: %w", err)
}
// Set the scope to ScopeExternal as the externalTrafficPolicy is set to Cluster.
fe = lb.NewL3n4Addr(proto, addrCluster, p, lb.ScopeExternal)
Expand Down Expand Up @@ -228,7 +228,7 @@ func getSanitizedLRPConfig(name, namespace string, uid types.UID, spec v2.Cilium
for i, portInfo := range svcMatcher.ToPorts {
p, pName, proto, err := portInfo.SanitizePortInfo(checkNamedPort)
if err != nil {
return nil, fmt.Errorf("invalid service matcher port %w", err)
return nil, fmt.Errorf("invalid service matcher port: %w", err)
}
// Set the scope to ScopeExternal as the externalTrafficPolicy is set to Cluster.
// frontend ip will later be populated with the clusterIP of the service.
Expand Down Expand Up @@ -258,7 +258,7 @@ func getSanitizedLRPConfig(name, namespace string, uid types.UID, spec v2.Cilium
for i, portInfo := range redirectTo.ToPorts {
p, pName, proto, err := portInfo.SanitizePortInfo(checkNamedPort)
if err != nil {
return nil, fmt.Errorf("invalid backend port %w", err)
return nil, fmt.Errorf("invalid backend port: %w", err)
}
beP := bePortInfo{
l4Addr: lb.L4Addr{
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ func (s *Service) UpdateBackendsState(backends []*lb.Backend) error {
logfields.BackendPreferred: b.Preferred,
}).Info("Persisting updated backend state for backend")
if err := s.lbmap.UpdateBackendWithState(b); err != nil {
errs = errors.Join(errs, fmt.Errorf("failed to update backend %+v %w", b, err))
errs = errors.Join(errs, fmt.Errorf("failed to update backend %+v: %w", b, err))
}
}

Expand Down Expand Up @@ -1919,7 +1919,7 @@ func (s *Service) updateBackendsCacheLocked(svc *svcInfo, backends []*lb.Backend
b.State = backends[i].State
// Update the persisted backend state in BPF maps.
if err := s.lbmap.UpdateBackendWithState(backends[i]); err != nil {
return nil, nil, nil, fmt.Errorf("failed to update backend %+v %w",
return nil, nil, nil, fmt.Errorf("failed to update backend %+v: %w",
backends[i], err)
}
case backends[i].Weight != b.Weight:
Expand Down
4 changes: 2 additions & 2 deletions pkg/versioncheck/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
func MustCompile(constraint string) semver.Range {
verCheck, err := Compile(constraint)
if err != nil {
panic(fmt.Errorf("cannot compile go-version constraint '%s' %w", constraint, err))
panic(fmt.Errorf("cannot compile go-version constraint '%s': %w", constraint, err))
}
return verCheck
}
Expand All @@ -36,7 +36,7 @@ func Compile(constraint string) (semver.Range, error) {
func MustVersion(version string) semver.Version {
ver, err := Version(version)
if err != nil {
panic(fmt.Errorf("cannot compile go-version version '%s' %w", version, err))
panic(fmt.Errorf("cannot compile go-version version '%s': %w", version, err))
}
return ver
}
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func (s *SSHMeta) PolicyRenderAndImport(policy string) (int, error) {
err := s.RenderTemplateToFile(filename, policy, os.ModePerm)
if err != nil {
s.logger.Errorf("PolicyRenderAndImport: cannot create policy file on '%s'", filename)
return 0, fmt.Errorf("cannot render the policy: %w", err)
return 0, fmt.Errorf("cannot render the policy: %w", err)
}
path := s.GetFilePath(filename)
s.logger.Debugf("PolicyRenderAndImport: import policy from '%s'", path)
Expand Down

0 comments on commit fe46958

Please sign in to comment.