src: lint: bump golangci-lint to 1.59, address unchecked fmt.Fprint*

This commit is contained in:
Rod Vagg
2024-06-06 19:51:39 +10:00
parent 59938414fc
commit 730c96ecaf
25 changed files with 212 additions and 143 deletions
+3 -3
View File
@@ -76,15 +76,15 @@ func NewAppFmt(a *ufcli.App) *AppFmt {
}
func (a *AppFmt) Print(args ...interface{}) {
fmt.Fprint(a.app.Writer, args...)
_, _ = fmt.Fprint(a.app.Writer, args...)
}
func (a *AppFmt) Println(args ...interface{}) {
fmt.Fprintln(a.app.Writer, args...)
_, _ = fmt.Fprintln(a.app.Writer, args...)
}
func (a *AppFmt) Printf(fmtstr string, args ...interface{}) {
fmt.Fprintf(a.app.Writer, fmtstr, args...)
_, _ = fmt.Fprintf(a.app.Writer, fmtstr, args...)
}
func (a *AppFmt) Scan(args ...interface{}) (int, error) {
+12 -2
View File
@@ -160,8 +160,18 @@ func infoCmdAct(cctx *cli.Context) error {
}
fmt.Printf("Bandwidth:\n")
fmt.Fprintf(tw, "\tTotalIn\tTotalOut\tRateIn\tRateOut\n")
fmt.Fprintf(tw, "\t%s\t%s\t%s/s\t%s/s\n", humanize.Bytes(uint64(s.TotalIn)), humanize.Bytes(uint64(s.TotalOut)), humanize.Bytes(uint64(s.RateIn)), humanize.Bytes(uint64(s.RateOut)))
if _, err := fmt.Fprintf(tw, "\tTotalIn\tTotalOut\tRateIn\tRateOut\n"); err != nil {
return err
}
if _, err := fmt.Fprintf(
tw,
"\t%s\t%s\t%s/s\t%s/s\n",
humanize.Bytes(uint64(s.TotalIn)),
humanize.Bytes(uint64(s.TotalOut)),
humanize.Bytes(uint64(s.RateIn)),
humanize.Bytes(uint64(s.RateOut))); err != nil {
return err
}
return tw.Flush()
}
+51 -18
View File
@@ -168,7 +168,7 @@ var msigCreateCmd = &cli.Command{
// check it executed successfully
if wait.Receipt.ExitCode.IsError() {
fmt.Fprintln(cctx.App.Writer, "actor creation failed!")
_, _ = fmt.Fprintln(cctx.App.Writer, "actor creation failed!")
return err
}
@@ -178,7 +178,7 @@ var msigCreateCmd = &cli.Command{
if err := execreturn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil {
return err
}
fmt.Fprintln(cctx.App.Writer, "Created new multisig: ", execreturn.IDAddress, execreturn.RobustAddress)
_, _ = fmt.Fprintln(cctx.App.Writer, "Created new multisig: ", execreturn.IDAddress, execreturn.RobustAddress)
// TODO: maybe register this somewhere
return nil
@@ -242,25 +242,25 @@ var msigInspectCmd = &cli.Command{
return err
}
fmt.Fprintf(cctx.App.Writer, "Balance: %s\n", types.FIL(act.Balance))
fmt.Fprintf(cctx.App.Writer, "Spendable: %s\n", types.FIL(types.BigSub(act.Balance, locked)))
_, _ = fmt.Fprintf(cctx.App.Writer, "Balance: %s\n", types.FIL(act.Balance))
_, _ = fmt.Fprintf(cctx.App.Writer, "Spendable: %s\n", types.FIL(types.BigSub(act.Balance, locked)))
if cctx.Bool("vesting") {
ib, err := mstate.InitialBalance()
if err != nil {
return err
}
fmt.Fprintf(cctx.App.Writer, "InitialBalance: %s\n", types.FIL(ib))
_, _ = fmt.Fprintf(cctx.App.Writer, "InitialBalance: %s\n", types.FIL(ib))
se, err := mstate.StartEpoch()
if err != nil {
return err
}
fmt.Fprintf(cctx.App.Writer, "StartEpoch: %d\n", se)
_, _ = fmt.Fprintf(cctx.App.Writer, "StartEpoch: %d\n", se)
ud, err := mstate.UnlockDuration()
if err != nil {
return err
}
fmt.Fprintf(cctx.App.Writer, "UnlockDuration: %d\n", ud)
_, _ = fmt.Fprintf(cctx.App.Writer, "UnlockDuration: %d\n", ud)
}
signers, err := mstate.Signers()
@@ -271,17 +271,17 @@ var msigInspectCmd = &cli.Command{
if err != nil {
return err
}
fmt.Fprintf(cctx.App.Writer, "Threshold: %d / %d\n", threshold, len(signers))
fmt.Fprintln(cctx.App.Writer, "Signers:")
_, _ = fmt.Fprintf(cctx.App.Writer, "Threshold: %d / %d\n", threshold, len(signers))
_, _ = fmt.Fprintln(cctx.App.Writer, "Signers:")
signerTable := tabwriter.NewWriter(cctx.App.Writer, 8, 4, 2, ' ', 0)
fmt.Fprintf(signerTable, "ID\tAddress\n")
_, _ = fmt.Fprintf(signerTable, "ID\tAddress\n")
for _, s := range signers {
signerActor, err := api.StateAccountKey(ctx, s, types.EmptyTSK)
if err != nil {
fmt.Fprintf(signerTable, "%s\t%s\n", s, "N/A")
_, _ = fmt.Fprintf(signerTable, "%s\t%s\n", s, "N/A")
} else {
fmt.Fprintf(signerTable, "%s\t%s\n", s, signerActor)
_, _ = fmt.Fprintf(signerTable, "%s\t%s\n", s, signerActor)
}
}
if err := signerTable.Flush(); err != nil {
@@ -297,7 +297,7 @@ var msigInspectCmd = &cli.Command{
}
decParams := cctx.Bool("decode-params")
fmt.Fprintln(cctx.App.Writer, "Transactions: ", len(pending))
_, _ = fmt.Fprintln(cctx.App.Writer, "Transactions: ", len(pending))
if len(pending) > 0 {
var txids []int64
for txid := range pending {
@@ -308,7 +308,7 @@ var msigInspectCmd = &cli.Command{
})
w := tabwriter.NewWriter(cctx.App.Writer, 8, 4, 2, ' ', 0)
fmt.Fprintf(w, "ID\tState\tApprovals\tTo\tValue\tMethod\tParams\n")
_, _ = fmt.Fprintf(w, "ID\tState\tApprovals\tTo\tValue\tMethod\tParams\n")
for _, txid := range txids {
tx := pending[txid]
target := tx.To.String()
@@ -320,9 +320,31 @@ var msigInspectCmd = &cli.Command{
if err != nil {
if tx.Method == 0 {
fmt.Fprintf(w, "%d\t%s\t%d\t%s\t%s\t%s(%d)\t%s\n", txid, "pending", len(tx.Approved), target, types.FIL(tx.Value), "Send", tx.Method, paramStr)
_, _ = fmt.Fprintf(
w,
"%d\t%s\t%d\t%s\t%s\t%s(%d)\t%s\n",
txid,
"pending",
len(tx.Approved),
target,
types.FIL(tx.Value),
"Send",
tx.Method,
paramStr,
)
} else {
fmt.Fprintf(w, "%d\t%s\t%d\t%s\t%s\t%s(%d)\t%s\n", txid, "pending", len(tx.Approved), target, types.FIL(tx.Value), "new account, unknown method", tx.Method, paramStr)
_, _ = fmt.Fprintf(
w,
"%d\t%s\t%d\t%s\t%s\t%s(%d)\t%s\n",
txid,
"pending",
len(tx.Approved),
target,
types.FIL(tx.Value),
"new account, unknown method",
tx.Method,
paramStr,
)
}
} else {
method := consensus.NewActorRegistry().Methods[targAct.Code][tx.Method] // TODO: use remote map
@@ -341,7 +363,18 @@ var msigInspectCmd = &cli.Command{
paramStr = string(b)
}
fmt.Fprintf(w, "%d\t%s\t%d\t%s\t%s\t%s(%d)\t%s\n", txid, "pending", len(tx.Approved), target, types.FIL(tx.Value), method.Name, tx.Method, paramStr)
_, _ = fmt.Fprintf(
w,
"%d\t%s\t%d\t%s\t%s\t%s(%d)\t%s\n",
txid,
"pending",
len(tx.Approved),
target,
types.FIL(tx.Value),
method.Name,
tx.Method,
paramStr,
)
}
}
if err := w.Flush(); err != nil {
@@ -923,7 +956,7 @@ var msigAddProposeCmd = &cli.Command{
msgCid := sm.Cid()
fmt.Fprintln(cctx.App.Writer, "sent add proposal in message: ", msgCid)
_, _ = fmt.Fprintln(cctx.App.Writer, "sent add proposal in message: ", msgCid)
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
if err != nil {
+27 -4
View File
@@ -479,7 +479,7 @@ var NetBandwidthCmd = &cli.Command{
tw := tabwriter.NewWriter(os.Stdout, 4, 4, 2, ' ', 0)
fmt.Fprintf(tw, "Segment\tTotalIn\tTotalOut\tRateIn\tRateOut\n")
_, _ = fmt.Fprintf(tw, "Segment\tTotalIn\tTotalOut\tRateIn\tRateOut\n")
if bypeer {
bw, err := api.NetBandwidthStatsByPeer(ctx)
@@ -498,7 +498,15 @@ var NetBandwidthCmd = &cli.Command{
for _, p := range peers {
s := bw[p]
fmt.Fprintf(tw, "%s\t%s\t%s\t%s/s\t%s/s\n", p, humanize.Bytes(uint64(s.TotalIn)), humanize.Bytes(uint64(s.TotalOut)), humanize.Bytes(uint64(s.RateIn)), humanize.Bytes(uint64(s.RateOut)))
_, _ = fmt.Fprintf(
tw,
"%s\t%s\t%s\t%s/s\t%s/s\n",
p,
humanize.Bytes(uint64(s.TotalIn)),
humanize.Bytes(uint64(s.TotalOut)),
humanize.Bytes(uint64(s.RateIn)),
humanize.Bytes(uint64(s.RateOut)),
)
}
} else if byproto {
bw, err := api.NetBandwidthStatsByProtocol(ctx)
@@ -520,7 +528,15 @@ var NetBandwidthCmd = &cli.Command{
if p == "" {
p = "<unknown>"
}
fmt.Fprintf(tw, "%s\t%s\t%s\t%s/s\t%s/s\n", p, humanize.Bytes(uint64(s.TotalIn)), humanize.Bytes(uint64(s.TotalOut)), humanize.Bytes(uint64(s.RateIn)), humanize.Bytes(uint64(s.RateOut)))
_, _ = fmt.Fprintf(
tw,
"%s\t%s\t%s\t%s/s\t%s/s\n",
p,
humanize.Bytes(uint64(s.TotalIn)),
humanize.Bytes(uint64(s.TotalOut)),
humanize.Bytes(uint64(s.RateIn)),
humanize.Bytes(uint64(s.RateOut)),
)
}
} else {
@@ -529,7 +545,14 @@ var NetBandwidthCmd = &cli.Command{
return err
}
fmt.Fprintf(tw, "Total\t%s\t%s\t%s/s\t%s/s\n", humanize.Bytes(uint64(s.TotalIn)), humanize.Bytes(uint64(s.TotalOut)), humanize.Bytes(uint64(s.RateIn)), humanize.Bytes(uint64(s.RateOut)))
_, _ = fmt.Fprintf(
tw,
"Total\t%s\t%s\t%s/s\t%s/s\n",
humanize.Bytes(uint64(s.TotalIn)),
humanize.Bytes(uint64(s.TotalOut)),
humanize.Bytes(uint64(s.RateIn)),
humanize.Bytes(uint64(s.RateOut)),
)
}
return tw.Flush()
+28 -24
View File
@@ -93,7 +93,7 @@ var paychAddFundsCmd = &cli.Command{
return err
}
fmt.Fprintln(cctx.App.Writer, chAddr)
_, _ = fmt.Fprintln(cctx.App.Writer, chAddr)
return nil
},
}
@@ -168,23 +168,23 @@ var paychStatusCmd = &cli.Command{
func paychStatus(writer io.Writer, avail *lapi.ChannelAvailableFunds) {
if avail.Channel == nil {
if avail.PendingWaitSentinel != nil {
fmt.Fprint(writer, "Creating channel\n")
fmt.Fprintf(writer, " From: %s\n", avail.From)
fmt.Fprintf(writer, " To: %s\n", avail.To)
fmt.Fprintf(writer, " Pending Amt: %s\n", types.FIL(avail.PendingAmt))
fmt.Fprintf(writer, " Wait Sentinel: %s\n", avail.PendingWaitSentinel)
_, _ = fmt.Fprint(writer, "Creating channel\n")
_, _ = fmt.Fprintf(writer, " From: %s\n", avail.From)
_, _ = fmt.Fprintf(writer, " To: %s\n", avail.To)
_, _ = fmt.Fprintf(writer, " Pending Amt: %s\n", types.FIL(avail.PendingAmt))
_, _ = fmt.Fprintf(writer, " Wait Sentinel: %s\n", avail.PendingWaitSentinel)
return
}
fmt.Fprint(writer, "Channel does not exist\n")
fmt.Fprintf(writer, " From: %s\n", avail.From)
fmt.Fprintf(writer, " To: %s\n", avail.To)
_, _ = fmt.Fprint(writer, "Channel does not exist\n")
_, _ = fmt.Fprintf(writer, " From: %s\n", avail.From)
_, _ = fmt.Fprintf(writer, " To: %s\n", avail.To)
return
}
if avail.PendingWaitSentinel != nil {
fmt.Fprint(writer, "Adding Funds to channel\n")
_, _ = fmt.Fprint(writer, "Adding Funds to channel\n")
} else {
fmt.Fprint(writer, "Channel exists\n")
_, _ = fmt.Fprint(writer, "Channel exists\n")
}
nameValues := [][]string{
@@ -204,7 +204,7 @@ func paychStatus(writer io.Writer, avail *lapi.ChannelAvailableFunds) {
avail.PendingWaitSentinel.String(),
})
}
fmt.Fprint(writer, formatNameValues(nameValues))
_, _ = fmt.Fprint(writer, formatNameValues(nameValues))
}
func formatNameValues(nameValues [][]string) string {
@@ -240,7 +240,7 @@ var paychListCmd = &cli.Command{
}
for _, v := range chs {
fmt.Fprintln(cctx.App.Writer, v.String())
_, _ = fmt.Fprintln(cctx.App.Writer, v.String())
}
return nil
},
@@ -281,7 +281,7 @@ var paychSettleCmd = &cli.Command{
return fmt.Errorf("settle message execution failed (exit code %d)", mwait.Receipt.ExitCode)
}
fmt.Fprintf(cctx.App.Writer, "Settled channel %s\n", ch)
_, _ = fmt.Fprintf(cctx.App.Writer, "Settled channel %s\n", ch)
return nil
},
}
@@ -321,7 +321,7 @@ var paychCloseCmd = &cli.Command{
return fmt.Errorf("collect message execution failed (exit code %d)", mwait.Receipt.ExitCode)
}
fmt.Fprintf(cctx.App.Writer, "Collected funds for channel %s\n", ch)
_, _ = fmt.Fprintf(cctx.App.Writer, "Collected funds for channel %s\n", ch)
return nil
},
}
@@ -381,7 +381,7 @@ var paychVoucherCreateCmd = &cli.Command{
}
if v.Voucher == nil {
return fmt.Errorf("Could not create voucher: insufficient funds in channel, shortfall: %d", v.Shortfall)
return fmt.Errorf("could not create voucher: insufficient funds in channel, shortfall: %d", v.Shortfall)
}
enc, err := EncodedString(v.Voucher)
@@ -389,7 +389,7 @@ var paychVoucherCreateCmd = &cli.Command{
return err
}
fmt.Fprintln(cctx.App.Writer, enc)
_, _ = fmt.Fprintln(cctx.App.Writer, enc)
return nil
},
}
@@ -425,7 +425,7 @@ var paychVoucherCheckCmd = &cli.Command{
return err
}
fmt.Fprintln(cctx.App.Writer, "voucher is valid")
_, _ = fmt.Fprintln(cctx.App.Writer, "voucher is valid")
return nil
},
}
@@ -580,12 +580,16 @@ func outputVoucher(w io.Writer, v *paych.SignedVoucher, export bool) error {
}
}
fmt.Fprintf(w, "Lane %d, Nonce %d: %s", v.Lane, v.Nonce, types.FIL(v.Amount))
if export {
fmt.Fprintf(w, "; %s", enc)
if _, err := fmt.Fprintf(w, "Lane %d, Nonce %d: %s", v.Lane, v.Nonce, types.FIL(v.Amount)); err != nil {
return err
}
fmt.Fprintln(w)
return nil
if export {
if _, err := fmt.Fprintf(w, "; %s", enc); err != nil {
return err
}
}
_, err := fmt.Fprintln(w)
return err
}
var paychVoucherSubmitCmd = &cli.Command{
@@ -629,7 +633,7 @@ var paychVoucherSubmitCmd = &cli.Command{
return fmt.Errorf("message execution failed (exit code %d)", mwait.Receipt.ExitCode)
}
fmt.Fprintln(cctx.App.Writer, "channel updated successfully")
_, _ = fmt.Fprintln(cctx.App.Writer, "channel updated successfully")
return nil
},
+1 -1
View File
@@ -217,7 +217,7 @@ var SendCmd = &cli.Command{
return err
}
fmt.Fprintf(cctx.App.Writer, "%s\n", sm.Cid())
_, _ = fmt.Fprintf(cctx.App.Writer, "%s\n", sm.Cid())
return nil
},
}
+6 -6
View File
@@ -28,7 +28,7 @@ func InteractiveSend(ctx context.Context, cctx *cli.Context, srv ServicesAPI,
printer := cctx.App.Writer
if xerrors.Is(err, ErrCheckFailed) {
if !cctx.Bool("interactive") {
fmt.Fprintf(printer, "Following checks have failed:\n")
_, _ = fmt.Fprintf(printer, "Following checks have failed:\n")
printChecks(printer, checks, proto.Message.Cid())
} else {
proto, err = resolveChecks(ctx, srv, cctx.App.Writer, proto, checks)
@@ -75,11 +75,11 @@ func resolveChecks(ctx context.Context, s ServicesAPI, printer io.Writer,
proto *api.MessagePrototype, checkGroups [][]api.MessageCheckStatus,
) (*api.MessagePrototype, error) {
fmt.Fprintf(printer, "Following checks have failed:\n")
_, _ = fmt.Fprintf(printer, "Following checks have failed:\n")
printChecks(printer, checkGroups, proto.Message.Cid())
if feeCapBad, baseFee := isFeeCapProblem(checkGroups, proto.Message.Cid()); feeCapBad {
fmt.Fprintf(printer, "Fee of the message can be adjusted\n")
_, _ = fmt.Fprintf(printer, "Fee of the message can be adjusted\n")
if askUser(printer, "Do you wish to do that? [Yes/no]: ", true) {
var err error
proto, err = runFeeCapAdjustmentUI(proto, baseFee)
@@ -91,7 +91,7 @@ func resolveChecks(ctx context.Context, s ServicesAPI, printer io.Writer,
if err != nil {
return nil, err
}
fmt.Fprintf(printer, "Following checks still failed:\n")
_, _ = fmt.Fprintf(printer, "Following checks still failed:\n")
printChecks(printer, checks, proto.Message.Cid())
}
@@ -114,14 +114,14 @@ func printChecks(printer io.Writer, checkGroups [][]api.MessageCheckStatus, prot
if !aboutProto {
msgName = c.Cid.String()
}
fmt.Fprintf(printer, "%s message failed a check %s: %s\n", msgName, c.Code, c.Err)
_, _ = fmt.Fprintf(printer, "%s message failed a check %s: %s\n", msgName, c.Code, c.Err)
}
}
}
func askUser(printer io.Writer, q string, def bool) bool {
var resp string
fmt.Fprint(printer, q)
_, _ = fmt.Fprint(printer, q)
_, _ = fmt.Scanln(&resp)
resp = strings.ToLower(resp)
if len(resp) == 0 {
+5 -5
View File
@@ -670,7 +670,7 @@ func ActorProposeChangeWorkerCmd(getActor ActorAddressGetter) *cli.Command {
}
if !cctx.Bool("really-do-it") {
fmt.Fprintln(cctx.App.Writer, "Pass --really-do-it to actually execute this action")
_, _ = fmt.Fprintln(cctx.App.Writer, "Pass --really-do-it to actually execute this action")
return nil
}
@@ -695,7 +695,7 @@ func ActorProposeChangeWorkerCmd(getActor ActorAddressGetter) *cli.Command {
return xerrors.Errorf("mpool push: %w", err)
}
fmt.Fprintln(cctx.App.Writer, "Propose Message CID:", smsg.Cid())
_, _ = fmt.Fprintln(cctx.App.Writer, "Propose Message CID:", smsg.Cid())
// wait for it to get mined into a block
wait, err := api.StateWaitMsg(ctx, smsg.Cid(), build.MessageConfidence)
@@ -716,8 +716,8 @@ func ActorProposeChangeWorkerCmd(getActor ActorAddressGetter) *cli.Command {
return fmt.Errorf("Proposed worker address change not reflected on chain: expected '%s', found '%s'", na, mi.NewWorker)
}
fmt.Fprintf(cctx.App.Writer, "Worker key change to %s successfully sent, change happens at height %d.\n", na, mi.WorkerChangeEpoch)
fmt.Fprintf(cctx.App.Writer, "If you have no active deadlines, call 'confirm-change-worker' at or after height %d to complete.\n", mi.WorkerChangeEpoch)
_, _ = fmt.Fprintf(cctx.App.Writer, "Worker key change to %s successfully sent, change happens at height %d.\n", na, mi.WorkerChangeEpoch)
_, _ = fmt.Fprintf(cctx.App.Writer, "If you have no active deadlines, call 'confirm-change-worker' at or after height %d to complete.\n", mi.WorkerChangeEpoch)
return nil
},
@@ -942,7 +942,7 @@ func ActorConfirmChangeWorkerCmd(getActor ActorAddressGetter) *cli.Command {
// check it executed successfully
if wait.Receipt.ExitCode.IsError() {
fmt.Fprintln(cctx.App.Writer, "Worker change failed!")
_, _ = fmt.Fprintln(cctx.App.Writer, "Worker change failed!")
return err
}