Skip to content

Commit

Permalink
fix: add error handling to resolve lint-errors
Browse files Browse the repository at this point in the history
fix: add error handling to resolve lint-errors
  • Loading branch information
rjan90 committed May 27, 2024
1 parent 1879570 commit c99bc2b
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 85 deletions.
2 changes: 1 addition & 1 deletion chain/types/fil.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (f FIL) Nano() string {
func (f FIL) Format(s fmt.State, ch rune) {
switch ch {
case 's', 'v':
fmt.Fprint(s, f.String())
_, _ = fmt.Fprint(s, f.String())
default:
f.Int.Format(s, ch)
}
Expand Down
12 changes: 8 additions & 4 deletions cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,9 @@ func outputStorageDeals(ctx context.Context, out io.Writer, full v0api.FullNode,

if verbose {
w := tabwriter.NewWriter(out, 2, 4, 2, ' ', 0)
fmt.Fprintf(w, "Created\tDealCid\tDealId\tProvider\tState\tOn Chain?\tSlashed?\tPieceCID\tSize\tPrice\tDuration\tTransferChannelID\tTransferStatus\tVerified\tMessage\n")
if _, err := fmt.Fprintf(w, "Created\tDealCid\tDealId\tProvider\tState\tOn Chain?\tSlashed?\tPieceCID\tSize\tPrice\tDuration\tTransferChannelID\tTransferStatus\tVerified\tMessage\n"); err != nil {
return err
}
for _, d := range deals {
onChain := "N"
if d.OnChainDealState.SectorStartEpoch() != -1 {
Expand Down Expand Up @@ -1832,7 +1834,7 @@ func outputStorageDeals(ctx context.Context, out io.Writer, full v0api.FullNode,
// transferPct = fmt.Sprintf("%d%%", pct)
//}
}
fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t%v\t%s\n",
if _, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t%v\t%s\n",
d.LocalDeal.CreationTime.Format(time.Stamp),
d.LocalDeal.ProposalCid,
d.LocalDeal.DealID,
Expand All @@ -1847,7 +1849,9 @@ func outputStorageDeals(ctx context.Context, out io.Writer, full v0api.FullNode,
transferChannelID,
transferStatus,
d.LocalDeal.Verified,
d.LocalDeal.Message)
d.LocalDeal.Message); err != nil {
return err
}
}
return w.Flush()
}
Expand Down Expand Up @@ -2329,7 +2333,7 @@ func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChann
}
_ = w.Flush(out)

fmt.Fprintf(out, "\nReceiving Channels\n\n")
_, _ = fmt.Fprintf(out, "\nReceiving Channels\n\n")
w = tablewriter.New(tablewriter.Col("ID"),
tablewriter.Col("Status"),
tablewriter.Col("Receiving From"),
Expand Down
6 changes: 3 additions & 3 deletions cli/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions cli/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,13 @@ 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()

}

func SyncBasefeeCheck(ctx context.Context, fullapi v1api.FullNode) error {
Expand Down
51 changes: 36 additions & 15 deletions cli/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ var msigCreateCmd = &cli.Command{

// check it executed successfully
if wait.Receipt.ExitCode.IsError() {
fmt.Fprintln(cctx.App.Writer, "actor creation failed!")
return err
if _, err := fmt.Fprintln(cctx.App.Writer, "actor creation failed!"); err != nil {
return err
}
}

// get address of newly created miner
Expand All @@ -178,8 +179,9 @@ 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)

if _, err := fmt.Fprintln(cctx.App.Writer, "Created new multisig: ", execreturn.IDAddress, execreturn.RobustAddress); err != nil {
return err
}
// TODO: maybe register this somewhere
return nil
},
Expand Down Expand Up @@ -242,25 +244,35 @@ 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)))
if _, err := fmt.Fprintf(cctx.App.Writer, "Balance: %s\n", types.FIL(act.Balance)); err != nil {
return err
}
if _, err := fmt.Fprintf(cctx.App.Writer, "Spendable: %s\n", types.FIL(types.BigSub(act.Balance, locked))); err != nil {
return err
}

if cctx.Bool("vesting") {
ib, err := mstate.InitialBalance()
if err != nil {
return err
}
fmt.Fprintf(cctx.App.Writer, "InitialBalance: %s\n", types.FIL(ib))
if _, err := fmt.Fprintf(cctx.App.Writer, "InitialBalance: %s\n", types.FIL(ib)); err != nil {
return err
}
se, err := mstate.StartEpoch()
if err != nil {
return err
}
fmt.Fprintf(cctx.App.Writer, "StartEpoch: %d\n", se)
if _, err := fmt.Fprintf(cctx.App.Writer, "StartEpoch: %d\n", se); err != nil {
return err
}
ud, err := mstate.UnlockDuration()
if err != nil {
return err
}
fmt.Fprintf(cctx.App.Writer, "UnlockDuration: %d\n", ud)
if _, err := fmt.Fprintf(cctx.App.Writer, "UnlockDuration: %d\n", ud); err != nil {
return err
}
}

signers, err := mstate.Signers()
Expand All @@ -271,11 +283,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:")
if _, err := fmt.Fprintf(cctx.App.Writer, "Threshold: %d / %d\n", threshold, len(signers)); err != nil {
return err
}
if _, err := fmt.Fprintln(cctx.App.Writer, "Signers:"); err != nil {
return err
}

signerTable := tabwriter.NewWriter(cctx.App.Writer, 8, 4, 2, ' ', 0)
fmt.Fprintf(signerTable, "ID\tAddress\n")
if _, err := fmt.Fprintf(signerTable, "ID\tAddress\n"); err != nil {
return err
}
for _, s := range signers {
signerActor, err := api.StateAccountKey(ctx, s, types.EmptyTSK)
if err != nil {
Expand All @@ -297,7 +315,9 @@ var msigInspectCmd = &cli.Command{
}

decParams := cctx.Bool("decode-params")
fmt.Fprintln(cctx.App.Writer, "Transactions: ", len(pending))
if _, err := fmt.Fprintln(cctx.App.Writer, "Transactions: ", len(pending)); err != nil {
return err
}
if len(pending) > 0 {
var txids []int64
for txid := range pending {
Expand Down Expand Up @@ -923,8 +943,9 @@ var msigAddProposeCmd = &cli.Command{

msgCid := sm.Cid()

fmt.Fprintln(cctx.App.Writer, "sent add proposal in message: ", msgCid)

if _, err := fmt.Fprintln(cctx.App.Writer, "sent add proposal in message: ", msgCid); err != nil {
return err
}
wait, err := api.StateWaitMsg(ctx, msgCid, uint64(cctx.Int("confidence")), build.Finality, true)
if err != nil {
return err
Expand Down
47 changes: 29 additions & 18 deletions cli/paych.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ var paychAddFundsCmd = &cli.Command{
return err
}

fmt.Fprintln(cctx.App.Writer, chAddr)
if _, err := fmt.Fprintln(cctx.App.Writer, chAddr); err != nil {
return err
}
restartRetrievals := cctx.Bool("restart-retrievals")
if restartRetrievals {
return api.ClientRetrieveTryRestartInsufficientFunds(ctx, chAddr)
Expand Down Expand Up @@ -177,23 +179,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{
Expand All @@ -213,7 +215,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 {
Expand Down Expand Up @@ -249,7 +251,9 @@ var paychListCmd = &cli.Command{
}

for _, v := range chs {
fmt.Fprintln(cctx.App.Writer, v.String())
if _, err := fmt.Fprintln(cctx.App.Writer, v.String()); err != nil {
return err
}
}
return nil
},
Expand Down Expand Up @@ -398,7 +402,9 @@ var paychVoucherCreateCmd = &cli.Command{
return err
}

fmt.Fprintln(cctx.App.Writer, enc)
if _, err := fmt.Fprintln(cctx.App.Writer, enc); err != nil {
return err
}
return nil
},
}
Expand Down Expand Up @@ -434,7 +440,9 @@ var paychVoucherCheckCmd = &cli.Command{
return err
}

fmt.Fprintln(cctx.App.Writer, "voucher is valid")
if _, err := fmt.Fprintln(cctx.App.Writer, "voucher is valid"); err != nil {
return err
}
return nil
},
}
Expand Down Expand Up @@ -593,7 +601,9 @@ func outputVoucher(w io.Writer, v *paych.SignedVoucher, export bool) error {
if export {
fmt.Fprintf(w, "; %s", enc)
}
fmt.Fprintln(w)
if _, err := fmt.Fprintln(w); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -638,8 +648,9 @@ var paychVoucherSubmitCmd = &cli.Command{
return fmt.Errorf("message execution failed (exit code %d)", mwait.Receipt.ExitCode)
}

fmt.Fprintln(cctx.App.Writer, "channel updated successfully")

if _, err := fmt.Fprintln(cctx.App.Writer, "channel updated successfully"); err != nil {
return err
}
return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion cli/sending_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func printChecks(printer io.Writer, checkGroups [][]api.MessageCheckStatus, prot

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 {
Expand Down
13 changes: 9 additions & 4 deletions cli/spcli/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,9 @@ 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")
if _, err := fmt.Fprintln(cctx.App.Writer, "Pass --really-do-it to actually execute this action"); err != nil {
return err
}
return nil
}

Expand All @@ -695,8 +697,9 @@ func ActorProposeChangeWorkerCmd(getActor ActorAddressGetter) *cli.Command {
return xerrors.Errorf("mpool push: %w", err)
}

fmt.Fprintln(cctx.App.Writer, "Propose Message CID:", smsg.Cid())

if _, err := fmt.Fprintln(cctx.App.Writer, "Propose Message CID:", smsg.Cid()); err != nil {
return err
}
// wait for it to get mined into a block
wait, err := api.StateWaitMsg(ctx, smsg.Cid(), build.MessageConfidence)
if err != nil {
Expand Down Expand Up @@ -942,7 +945,9 @@ func ActorConfirmChangeWorkerCmd(getActor ActorAddressGetter) *cli.Command {

// check it executed successfully
if wait.Receipt.ExitCode.IsError() {
fmt.Fprintln(cctx.App.Writer, "Worker change failed!")
if _, err := fmt.Fprintln(cctx.App.Writer, "Worker change failed!"); err != nil {
return err
}
return err
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/lotus-miner/pieces.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ var piecesInfoCmd = &cli.Command{

fmt.Println("Piece: ", pi.PieceCID)
w := tabwriter.NewWriter(os.Stdout, 4, 4, 2, ' ', 0)
fmt.Fprintln(w, "Deals:\nDealID\tSectorID\tLength\tOffset")
if _, err := fmt.Fprintln(w, "Deals:\nDealID\tSectorID\tLength\tOffset"); err != nil {
return err
}
for _, d := range pi.Deals {
fmt.Fprintf(w, "%d\t%d\t%d\t%d\n", d.DealID, d.SectorID, d.Length, d.Offset)
}
Expand Down
Loading

0 comments on commit c99bc2b

Please sign in to comment.