Skip to content

Commit

Permalink
add error replace errorf in some func
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS authored and anrs committed Oct 27, 2022
1 parent 45c7e5e commit 5e76472
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 87 deletions.
2 changes: 1 addition & 1 deletion client/utils/servicepusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (p *EndpointPusher) addCheck(endpoints []string) {
func (p *EndpointPusher) pollReachability(ctx context.Context, endpoint string) {
parts := strings.Split(endpoint, ":")
if len(parts) != 2 {
log.Errorf(ctx, nil, "[EruResolver] wrong format of endpoint: %s", endpoint)
log.Errorf(ctx, types.ErrInvalidType, "[EruResolver] wrong format of endpoint: %s", endpoint)
return
}

Expand Down
12 changes: 6 additions & 6 deletions cluster/calcium/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ func (c *Calcium) BuildImage(ctx context.Context, opts *types.BuildOptions) (ch
logger := log.WithField("Calcium", "BuildImage").WithField("opts", opts)
// Disable build API if scm not set
if c.source == nil {
logger.Errorf(ctx, types.ErrSCMNotSet, "")
logger.Error(ctx, types.ErrSCMNotSet)
return nil, types.ErrSCMNotSet
}
// select nodes
node, err := c.selectBuildNode(ctx)
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}

Expand All @@ -44,15 +44,15 @@ func (c *Calcium) BuildImage(ctx context.Context, opts *types.BuildOptions) (ch
case types.BuildFromExist:
refs, node, resp, err = c.buildFromExist(ctx, opts)
default:
logger.Errorf(ctx, types.ErrUnknownBuildType, "")
logger.Error(ctx, types.ErrUnknownBuildType)
return nil, types.ErrUnknownBuildType
}
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}
ch, err = c.pushImageAndClean(ctx, resp, node, refs)
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return ch, err
}

Expand Down Expand Up @@ -171,7 +171,7 @@ func (c *Calcium) pushImageAndClean(ctx context.Context, resp io.ReadCloser, nod
log.Infof(ctx, "[BuildImage] Push image %s", tag)
rc, err := node.Engine.ImagePush(ctx, tag)
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
ch <- &types.BuildImageMessage{Error: err.Error()}
continue
}
Expand Down
10 changes: 5 additions & 5 deletions cluster/calcium/calcium.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func New(ctx context.Context, config types.Config, t *testing.T) (*Calcium, erro
// set store
store, err := store.NewStore(config, t)
if err != nil {
log.Errorf(ctx, err, "")
log.Error(ctx, err)
return nil, err
}

Expand All @@ -65,7 +65,7 @@ func New(ctx context.Context, config types.Config, t *testing.T) (*Calcium, erro
// set resource plugin manager
rmgr, err := resources.NewPluginsManager(config)
if err != nil {
log.Errorf(ctx, err, "")
log.Error(ctx, err)
return nil, err
}

Expand Down Expand Up @@ -96,18 +96,18 @@ func New(ctx context.Context, config types.Config, t *testing.T) (*Calcium, erro

cal.wal, err = enableWAL(config, cal, store)
if err != nil {
log.Errorf(ctx, err, "")
log.Error(ctx, err)
return nil, err
}

cal.identifier, err = config.Identifier()
if err != nil {
log.Errorf(ctx, err, "")
log.Error(ctx, err)
return nil, err
}

_ = pool.Invoke(func() { cal.InitMetrics(ctx) })
log.Errorf(ctx, err, "")
log.Error(ctx, err)
return cal, err
}

Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (c *Calcium) ControlWorkload(ctx context.Context, ids []string, t string, f
logger.Infof(ctx, "%v", "[ControlWorkload] Hook Output:")
logger.Infof(ctx, "%v", string(utils.MergeHookOutputs(message)))
}
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
ch <- &types.ControlWorkloadMessage{
WorkloadID: id,
Error: err,
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func (c *Calcium) Copy(ctx context.Context, opts *types.CopyOptions) (chan *types.CopyMessage, error) {
logger := log.WithField("Calcium", "Copy").WithField("opts", opts)
if err := opts.Validate(); err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}

Expand All @@ -34,7 +34,7 @@ func (c *Calcium) Copy(ctx context.Context, opts *types.CopyOptions) (chan *type
workload, err := c.GetWorkload(ctx, id)
if err != nil {
for _, path := range paths {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
ch <- &types.CopyMessage{
ID: id,
Path: path,
Expand Down
12 changes: 6 additions & 6 deletions cluster/calcium/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
func (c *Calcium) CreateWorkload(ctx context.Context, opts *types.DeployOptions) (chan *types.CreateWorkloadMessage, error) {
logger := log.WithField("Calcium", "CreateWorkload").WithField("opts", opts)
if err := opts.Validate(); err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}

Expand All @@ -32,7 +32,7 @@ func (c *Calcium) CreateWorkload(ctx context.Context, opts *types.DeployOptions)
// Count 要大于0
if opts.Count <= 0 {
err := types.NewDetailedErr(types.ErrBadCount, opts.Count)
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}

Expand Down Expand Up @@ -97,7 +97,7 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio
func(ctx context.Context) (err error) {
defer func() {
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
ch <- &types.CreateWorkloadMessage{Error: err}
}
}()
Expand Down Expand Up @@ -156,7 +156,7 @@ func (c *Calcium) doCreateWorkloads(ctx context.Context, opts *types.DeployOptio
})
return c.rmgr.RollbackAlloc(ctx, nodename, resourceArgsToRollback)
}); e != nil {
logger.Errorf(ctx, e, "")
logger.Error(ctx, e)
err = e
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func (c *Calcium) doDeployWorkloadsOnNode(ctx context.Context,
node, err := c.doGetAndPrepareNode(ctx, nodename, opts.Image)
if err != nil {
for i := 0; i < deploy; i++ {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
ch <- &types.CreateWorkloadMessage{Error: err}
}
return utils.Range(deploy), err
Expand All @@ -250,7 +250,7 @@ func (c *Calcium) doDeployWorkloadsOnNode(ctx context.Context,
defer func() {
if e != nil {
err = e
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
createMsg.Error = err
appendLock.Lock()
indices = append(indices, idx)
Expand Down
22 changes: 11 additions & 11 deletions cluster/calcium/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import (
func (c *Calcium) CacheImage(ctx context.Context, opts *types.ImageOptions) (chan *types.CacheImageMessage, error) {
logger := log.WithField("Calcium", "CacheImage").WithField("opts", opts)
if err := opts.Validate(); err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}

nodes, err := c.filterNodes(ctx, &types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}

if len(nodes) == 0 {
logger.Errorf(ctx, types.ErrPodNoNodes, "")
logger.Error(ctx, types.ErrPodNoNodes)
return nil, types.ErrPodNoNodes
}

Expand All @@ -49,7 +49,7 @@ func (c *Calcium) CacheImage(ctx context.Context, opts *types.ImageOptions) (cha
Message: "",
}
if err := pullImage(ctx, node, image); err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
m.Success = false
m.Message = err.Error()
}
Expand All @@ -66,18 +66,18 @@ func (c *Calcium) CacheImage(ctx context.Context, opts *types.ImageOptions) (cha
func (c *Calcium) RemoveImage(ctx context.Context, opts *types.ImageOptions) (chan *types.RemoveImageMessage, error) {
logger := log.WithField("Calcium", "RemoveImage").WithField("opts", opts)
if err := opts.Validate(); err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}

nodes, err := c.filterNodes(ctx, &types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}

if len(nodes) == 0 {
logger.Errorf(ctx, types.ErrPodNoNodes, "")
logger.Error(ctx, types.ErrPodNoNodes)
return nil, types.ErrPodNoNodes
}

Expand All @@ -99,7 +99,7 @@ func (c *Calcium) RemoveImage(ctx context.Context, opts *types.ImageOptions) (ch
Messages: []string{},
}
if removeItems, err := node.Engine.ImageRemove(ctx, image, false, true); err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
m.Messages = append(m.Messages, err.Error())
} else {
m.Success = true
Expand Down Expand Up @@ -129,12 +129,12 @@ func (c *Calcium) ListImage(ctx context.Context, opts *types.ImageOptions) (chan

nodes, err := c.filterNodes(ctx, &types.NodeFilter{Podname: opts.Podname, Includes: opts.Nodenames})
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}

if len(nodes) == 0 {
logger.Errorf(ctx, types.ErrPodNoNodes, "")
logger.Error(ctx, types.ErrPodNoNodes)
return nil, types.ErrPodNoNodes
}

Expand All @@ -155,7 +155,7 @@ func (c *Calcium) ListImage(ctx context.Context, opts *types.ImageOptions) (chan
Error: nil,
}
if images, err := node.Engine.ImageList(ctx, opts.Filter); err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
msg.Error = err
} else {
for _, image := range images {
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *Calcium) RunAndWait(ctx context.Context, opts *types.DeployOptions, inC

logger := log.WithField("Calcium", "RunAndWait").WithField("opts", opts)
if err := opts.Validate(); err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return workloadIDs, nil, err
}
opts.Lambda = true
Expand Down Expand Up @@ -68,7 +68,7 @@ func (c *Calcium) RunAndWait(ctx context.Context, opts *types.DeployOptions, inC

commit, err := c.wal.Log(eventCreateLambda, message.WorkloadID)
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return &types.AttachWorkloadMessage{
WorkloadID: message.WorkloadID,
Data: []byte(fmt.Sprintf("Create wal failed: %s, %+v", message.WorkloadID, err)),
Expand Down
4 changes: 2 additions & 2 deletions cluster/calcium/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (c *Calcium) LogStream(ctx context.Context, opts *types.LogStreamOptions) (
defer close(ch)
workload, err := c.GetWorkload(ctx, opts.ID)
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
ch <- &types.LogStreamMessage{ID: opts.ID, Error: err}
return
}
Expand All @@ -31,7 +31,7 @@ func (c *Calcium) LogStream(ctx context.Context, opts *types.LogStreamOptions) (
Stdout: true,
Stderr: true,
})
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
if err != nil {
ch <- &types.LogStreamMessage{ID: opts.ID, Error: err}
return
Expand Down
14 changes: 7 additions & 7 deletions cluster/calcium/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ func (c *Calcium) ListNetworks(ctx context.Context, podname string, driver strin
networks := []*enginetypes.Network{}
nodes, err := c.store.GetNodesByPod(ctx, &types.NodeFilter{Podname: podname})
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return networks, err
}

if len(nodes) == 0 {
err := types.NewDetailedErr(types.ErrPodNoNodes, podname)
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return networks, err
}

Expand All @@ -35,7 +35,7 @@ func (c *Calcium) ListNetworks(ctx context.Context, podname string, driver strin
node := nodes[0]

networks, err = node.Engine.NetworkList(ctx, drivers)
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return networks, err
}

Expand All @@ -44,12 +44,12 @@ func (c *Calcium) ConnectNetwork(ctx context.Context, network, target, ipv4, ipv
logger := log.WithField("Calcium", "ConnectNetwork").WithField("network", network).WithField("target", target).WithField("ipv4", ipv4).WithField("ipv6", ipv6)
workload, err := c.GetWorkload(ctx, target)
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return nil, err
}

networks, err := workload.Engine.NetworkConnect(ctx, network, target, ipv4, ipv6)
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return networks, err
}

Expand All @@ -58,11 +58,11 @@ func (c *Calcium) DisconnectNetwork(ctx context.Context, network, target string,
logger := log.WithField("Calcium", "DisconnectNetwork").WithField("network", network).WithField("target", target).WithField("force", force)
workload, err := c.GetWorkload(ctx, target)
if err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
return err
}
if err = workload.Engine.NetworkDisconnect(ctx, network, target, force); err != nil {
logger.Errorf(ctx, err, "")
logger.Error(ctx, err)
}
return err
}
Loading

0 comments on commit 5e76472

Please sign in to comment.