Skip to content

Commit

Permalink
Make all error keys in logs consistent (#9718)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsondav authored Jul 3, 2023
1 parent 8d3cd36 commit 9229d28
Show file tree
Hide file tree
Showing 33 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion common/txmgr/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) ethT
}
addr, err := eb.parseAddr(ev.Payload)
if err != nil {
eb.logger.Errorw("failed to parse address in trigger", "error", err)
eb.logger.Errorw("failed to parse address in trigger", "err", err)
continue
}
eb.Trigger(addr)
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Reb
errMu.Lock()
errors = append(errors, err)
errMu.Unlock()
ec.lggr.Errorw("Error in RebroadcastWhereNecessary", "error", err, "fromAddress", fromAddress)
ec.lggr.Errorw("Error in RebroadcastWhereNecessary", "err", err, "fromAddress", fromAddress)
}

wg.Done()
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/log/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func (b *broadcaster) onReplayRequest(replayReq replayRequest) {
err := b.orm.MarkBroadcastsUnconsumed(replayReq.fromBlock, pg.WithParentCtx(ctx), pg.WithLongQueryTimeout())
if err != nil {
b.logger.Errorw("Error marking broadcasts as unconsumed",
"error", err, "fromBlock", replayReq.fromBlock)
"err", err, "fromBlock", replayReq.fromBlock)
}
}
b.logger.Debugw(
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/log/registrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (r *handler) sendLog(log types.Log, latestHead evmtypes.Head,
// Create unconsumed broadcast
if err := bc.CreateBroadcast(log.BlockHash, log.BlockNumber, log.Index, jobID); err != nil {
logger.Errorw("Could not create broadcast log", "blockNumber", log.BlockNumber,
"blockHash", log.BlockHash, "address", log.Address, "jobID", jobID, "error", err)
"blockHash", log.BlockHash, "address", log.Address, "jobID", jobID, "err", err)
continue
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/monitor/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ func (w *worker) checkAccountBalance(ctx context.Context, address gethCommon.Add
bal, err := w.bm.ethClient.BalanceAt(ctx, address, nil)
if err != nil {
w.bm.logger.Errorw(fmt.Sprintf("BalanceMonitor: error getting balance for key %s", address.Hex()),
"error", err,
"err", err,
"address", address,
)
} else if bal == nil {
w.bm.logger.Errorw(fmt.Sprintf("BalanceMonitor: error getting balance for key %s: invariant violation, bal may not be nil", address.Hex()),
"error", err,
"err", err,
"address", address,
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (c *evmTxmClient) BatchSendTransactions(ctx context.Context, updateBroadcas
if len(reqs) != len(attempts) {
lenErr := fmt.Errorf("Returned request data length (%d) != number of tx attempts (%d)", len(reqs), len(attempts))
err = errors.Join(err, lenErr)
lggr.Criticalw("Mismatched length", "error", err)
lggr.Criticalw("Mismatched length", "err", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion core/chains/solana/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (c *chain) getClient() (client.ReaderWriter, error) {
client, err = c.verifiedClient(node)
// if error, try another node
if err != nil {
c.lggr.Warnw("failed to create node", "name", node.Name, "solana-url", node.SolanaURL, "error", err.Error())
c.lggr.Warnw("failed to create node", "name", node.Name, "solana-url", node.SolanaURL, "err", err.Error())
continue
}
// if all checks passed, mark found and break loop
Expand Down
2 changes: 1 addition & 1 deletion core/chains/starknet/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *chain) getClient() (*starknet.Client, error) {
client, err = starknet.NewClient(node.ChainID, node.URL, c.lggr, &timeout)
// if error, try another node
if err != nil {
c.lggr.Warnw("failed to create node", "name", node.Name, "starknet-url", node.URL, "error", err.Error())
c.lggr.Warnw("failed to create node", "name", node.Name, "starknet-url", node.URL, "err", err.Error())
continue
}
// if all checks passed, mark found and break loop
Expand Down
4 changes: 2 additions & 2 deletions core/services/blockhashstore/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func GetUnfulfilledBlocksAndRequests(
reqs, err := coordinator.Requests(ctx, uint64(fromBlock), uint64(toBlock))
if err != nil {
lggr.Errorw("Failed to fetch VRF requests",
"error", err)
"err", err)
return nil, errors.Wrap(err, "fetching VRF requests")
}
for _, req := range reqs {
Expand All @@ -70,7 +70,7 @@ func GetUnfulfilledBlocksAndRequests(
fuls, err := coordinator.Fulfillments(ctx, uint64(fromBlock))
if err != nil {
lggr.Errorw("Failed to fetch VRF fulfillments",
"error", err)
"err", err)
return nil, errors.Wrap(err, "fetching VRF fulfillments")
}
for _, ful := range fuls {
Expand Down
2 changes: 1 addition & 1 deletion core/services/blockhashstore/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,6 @@ func (s *service) runFeeder() {
s.logger.Debugw("BHS feeder run completed successfully")
} else {
s.logger.Errorw("BHS feeder run was at least partially unsuccessful",
"error", err)
"err", err)
}
}
6 changes: 3 additions & 3 deletions core/services/blockhashstore/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Feeder struct {
func (f *Feeder) Run(ctx context.Context) error {
latestBlock, err := f.latestBlock(ctx)
if err != nil {
f.lggr.Errorw("Failed to fetch current block number", "error", err)
f.lggr.Errorw("Failed to fetch current block number", "err", err)
return errors.Wrap(err, "fetching block number")
}

Expand Down Expand Up @@ -76,7 +76,7 @@ func (f *Feeder) Run(ctx context.Context) error {
stored, err := f.bhs.IsStored(ctx, block)
if err != nil {
f.lggr.Errorw("Failed to check if block is already stored, attempting to store anyway",
"error", err,
"err", err,
"block", block)
errs = multierr.Append(errs, errors.Wrap(err, "checking if stored"))
} else if stored {
Expand All @@ -90,7 +90,7 @@ func (f *Feeder) Run(ctx context.Context) error {
// Block needs to be stored
err = f.bhs.Store(ctx, block)
if err != nil {
f.lggr.Errorw("Failed to store block", "error", err, "block", block)
f.lggr.Errorw("Failed to store block", "err", err, "block", block)
errs = multierr.Append(errs, errors.Wrap(err, "storing block"))
continue
}
Expand Down
4 changes: 2 additions & 2 deletions core/services/blockheaderfeeder/block_header_feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type BlockHeaderFeeder struct {
func (f *BlockHeaderFeeder) Run(ctx context.Context) error {
latestBlockNumber, err := f.latestBlock(ctx)
if err != nil {
f.lggr.Errorw("Failed to fetch current block number", "error", err)
f.lggr.Errorw("Failed to fetch current block number", "err", err)
return errors.Wrap(err, "fetching block number")
}

Expand Down Expand Up @@ -204,7 +204,7 @@ func (f *BlockHeaderFeeder) findLowestBlockNumberWithoutBlockhash(ctx context.Co
stored, err := f.bhs.IsStored(ctx, block)
if err != nil {
lggr.Warnw("Failed to check if block is already stored",
"error", err,
"err", err,
"block", block)
continue
} else if stored {
Expand Down
2 changes: 1 addition & 1 deletion core/services/blockheaderfeeder/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (s *service) runFeeder() {
s.logger.Debugw("BlockHeaderFeeder run completed successfully")
} else {
s.logger.Errorw("BlockHeaderFeeder run was at least partially unsuccessful",
"error", err)
"err", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/services/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (cr *Cron) Start(context.Context) error {

_, err := cr.cronRunner.AddFunc(cr.jobSpec.CronSpec.CronSchedule, cr.runPipeline)
if err != nil {
cr.logger.Errorw(fmt.Sprintf("Error running cron job %d", cr.jobSpec.ID), "error", err, "schedule", cr.jobSpec.CronSpec.CronSchedule, "jobID", cr.jobSpec.ID)
cr.logger.Errorw(fmt.Sprintf("Error running cron job %d", cr.jobSpec.ID), "err", err, "schedule", cr.jobSpec.CronSpec.CronSchedule, "jobID", cr.jobSpec.ID)
return err
}
cr.cronRunner.Start()
Expand Down
2 changes: 1 addition & 1 deletion core/services/directrequest/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (l *listener) handleReceivedLogs(mailbox *utils.Mailbox[log.Broadcast]) {
}
was, err := l.logBroadcaster.WasAlreadyConsumed(lb)
if err != nil {
l.logger.Errorw("Could not determine if log was already consumed", "error", err)
l.logger.Errorw("Could not determine if log was already consumed", "err", err)
continue
} else if was {
continue
Expand Down
18 changes: 9 additions & 9 deletions core/services/feeds/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (s *service) DeleteJob(ctx context.Context, args *DeleteJobArgs) (int64, er

pctx := pg.WithParentCtx(ctx)
if err = s.orm.DeleteProposal(proposal.ID, pctx); err != nil {
s.lggr.Errorw("Failed to delete the proposal", "error", err)
s.lggr.Errorw("Failed to delete the proposal", "err", err)

return 0, errors.Wrap(err, "DeleteProposal failed")
}
Expand Down Expand Up @@ -489,7 +489,7 @@ func (s *service) RevokeJob(ctx context.Context, args *RevokeJobArgs) (int64, er

pctx := pg.WithParentCtx(ctx)
if err = s.orm.RevokeSpec(latest.ID, pctx); err != nil {
s.lggr.Errorw("Failed to revoke the proposal", "error", err)
s.lggr.Errorw("Failed to revoke the proposal", "err", err)

return 0, errors.Wrap(err, "RevokeSpec failed")
}
Expand Down Expand Up @@ -682,7 +682,7 @@ func (s *service) ApproveSpec(ctx context.Context, id int64, force bool) error {

fmsClient, err := s.connMgr.GetClient(proposal.FeedsManagerID)
if err != nil {
logger.Errorw("Failed to get FMS Client", "error", err)
logger.Errorw("Failed to get FMS Client", "err", err)

return errors.Wrap(err, "fms rpc client")
}
Expand Down Expand Up @@ -764,7 +764,7 @@ func (s *service) ApproveSpec(ctx context.Context, id int64, force bool) error {
approvedSpec, serr := s.orm.GetApprovedSpec(proposal.ID, pgOpts)
if serr != nil {
if !errors.Is(serr, sql.ErrNoRows) {
logger.Errorw("Failed to get approved spec", "error", serr)
logger.Errorw("Failed to get approved spec", "err", serr)

// Return an error for any other errors fetching the
// approved spec
Expand All @@ -775,30 +775,30 @@ func (s *service) ApproveSpec(ctx context.Context, id int64, force bool) error {
// If a spec is found, cancel the existing job spec
if serr == nil {
if cerr := s.orm.CancelSpec(approvedSpec.ID, pgOpts); cerr != nil {
logger.Errorw("Failed to delete the cancel the spec", "error", cerr)
logger.Errorw("Failed to delete the cancel the spec", "err", cerr)

return cerr
}
}

// Delete the job
if serr = s.jobSpawner.DeleteJob(existingJobID, pgOpts); serr != nil {
logger.Errorw("Failed to delete the job", "error", serr)
logger.Errorw("Failed to delete the job", "err", serr)

return errors.Wrap(serr, "DeleteJob failed")
}
}

// Create the job
if txerr = s.jobSpawner.CreateJob(j, pgOpts); txerr != nil {
logger.Errorw("Failed to create job", "error", txerr)
logger.Errorw("Failed to create job", "err", txerr)

return txerr
}

// Approve the job proposal spec
if txerr = s.orm.ApproveSpec(id, j.ExternalJobID, pgOpts); txerr != nil {
logger.Errorw("Failed to approve spec", "error", txerr)
logger.Errorw("Failed to approve spec", "err", txerr)

return txerr
}
Expand All @@ -808,7 +808,7 @@ func (s *service) ApproveSpec(ctx context.Context, id int64, force bool) error {
Uuid: proposal.RemoteUUID.String(),
Version: int64(spec.Version),
}); txerr != nil {
logger.Errorw("Failed to approve job to FMS", "error", txerr)
logger.Errorw("Failed to approve job to FMS", "err", txerr)

return txerr
}
Expand Down
2 changes: 1 addition & 1 deletion core/services/functions/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (l *FunctionsListener) processOracleEvents() {
}
was, err := l.logBroadcaster.WasAlreadyConsumed(lb)
if err != nil {
l.logger.Errorw("Could not determine if log was already consumed", "error", err)
l.logger.Errorw("Could not determine if log was already consumed", "err", err)
continue
} else if was {
continue
Expand Down
12 changes: 6 additions & 6 deletions core/services/job/spawner.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (js *spawner) stopService(jobID int32) {
service := aj.services[i]
err := service.Close()
if err != nil {
js.lggr.Criticalw("Error stopping job service", "jobID", jobID, "error", err, "subservice", i, "serviceType", reflect.TypeOf(service))
js.lggr.Criticalw("Error stopping job service", "jobID", jobID, "err", err, "subservice", i, "serviceType", reflect.TypeOf(service))
js.SvcErrBuffer.Append(pkgerrors.Wrap(err, "error stopping job service"))
} else {
js.lggr.Debugw("Stopped job service", "jobID", jobID, "subservice", i, "serviceType", fmt.Sprintf("%T", service))
Expand Down Expand Up @@ -201,7 +201,7 @@ func (js *spawner) StartService(ctx context.Context, jb Job) error {

srvs, err := delegate.ServicesForSpec(jb)
if err != nil {
js.lggr.Errorw("Error creating services for job", "jobID", jb.ID, "error", err)
js.lggr.Errorw("Error creating services for job", "jobID", jb.ID, "err", err)
cctx, cancel := js.chStop.NewCtx()
defer cancel()
js.orm.TryRecordError(jb.ID, err.Error(), pg.WithParentCtx(cctx))
Expand All @@ -215,7 +215,7 @@ func (js *spawner) StartService(ctx context.Context, jb Job) error {
for _, srv := range srvs {
err = ms.Start(ctx, srv)
if err != nil {
js.lggr.Critical("Error starting service for job", "jobID", jb.ID, "error", err)
js.lggr.Critical("Error starting service for job", "jobID", jb.ID, "err", err)
return err
}
aj.services = append(aj.services, srv)
Expand Down Expand Up @@ -244,15 +244,15 @@ func (js *spawner) CreateJob(jb *Job, qopts ...pg.QOpt) (err error) {

err = js.orm.CreateJob(jb, pg.WithQueryer(q.Queryer), pg.WithParentCtx(ctx))
if err != nil {
js.lggr.Errorw("Error creating job", "type", jb.Type, "error", err)
js.lggr.Errorw("Error creating job", "type", jb.Type, "err", err)
return
}
js.lggr.Infow("Created job", "type", jb.Type, "jobID", jb.ID)

delegate.BeforeJobCreated(*jb)
err = js.StartService(pctx, *jb)
if err != nil {
js.lggr.Errorw("Error starting job services", "type", jb.Type, "jobID", jb.ID, "error", err)
js.lggr.Errorw("Error starting job services", "type", jb.Type, "jobID", jb.ID, "err", err)
} else {
js.lggr.Infow("Started job services", "type", jb.Type, "jobID", jb.ID)
}
Expand Down Expand Up @@ -310,7 +310,7 @@ func (js *spawner) DeleteJob(jobID int32, qopts ...pg.QOpt) error {
err := q.Transaction(func(tx pg.Queryer) error {
err := js.orm.DeleteJob(jobID, pg.WithQueryer(tx))
if err != nil {
js.lggr.Errorw("Error deleting job", "jobID", jobID, "error", err)
js.lggr.Errorw("Error deleting job", "jobID", jobID, "err", err)
return err
}
// This comes after calling orm.DeleteJob(), so that any non-db side effects inside it only get executed if
Expand Down
2 changes: 1 addition & 1 deletion core/services/keeper/registry_synchronizer_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (rs *RegistrySynchronizer) syncUpkeepWithCallback(getter upkeepGetter, regi
defer doneCallback()

if err := rs.syncUpkeep(getter, registry, upkeepID); err != nil {
rs.logger.With("error", err.Error()).With(
rs.logger.With("err", err.Error()).With(
"upkeepID", NewUpkeepIdentifier(upkeepID).String(),
"registryContract", registry.ContractAddress.Hex(),
).Error("unable to sync upkeep on registry")
Expand Down
4 changes: 2 additions & 2 deletions core/services/keeper/registry_synchronizer_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestSyncUpkeepWithCallback_UpkeepNotFound(t *testing.T) {
for _, entry := range logObserver.All() {
for _, field := range entry.Context {
switch field.Key {
case "error":
case "err":
require.Equal(t, "failed to get upkeep config: failure in calling contract [chain connection error example]: getConfig v1.2", field.String)
case "upkeepID":
require.Equal(t, fmt.Sprintf("UPx%064s", "429ab990419450db80821"), field.String)
Expand All @@ -71,6 +71,6 @@ func TestSyncUpkeepWithCallback_UpkeepNotFound(t *testing.T) {
}
}

require.Equal(t, map[string]bool{"upkeepID": true, "error": true, "registryContract": true}, keys)
require.Equal(t, map[string]bool{"upkeepID": true, "err": true, "registryContract": true}, keys)
require.Equal(t, 1, count, "callback function should run")
}
Loading

0 comments on commit 9229d28

Please sign in to comment.