Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add Error Handling to Resolve Linting Errors #12046

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 12 additions & 5 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 @@ -2315,7 +2319,10 @@ func OutputDataTransferChannels(out io.Writer, channels []lapi.DataTransferChann
}
}

fmt.Fprintf(out, "Sending Channels\n\n")
if _, err := fmt.Fprintf(out, "Sending Channels\n\n"); err != nil {
fmt.Fprintf(os.Stderr, "Error writing to output: %v\n", err)
return
}
w := tablewriter.New(tablewriter.Col("ID"),
tablewriter.Col("Status"),
tablewriter.Col("Sending To"),
Expand All @@ -2329,7 +2336,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
75 changes: 54 additions & 21 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore the error and return err - this branch always return err anyway

}
}

// 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,17 +283,27 @@ 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 {
fmt.Fprintf(signerTable, "%s\t%s\n", s, "N/A")
if _, err := fmt.Fprintf(signerTable, "%s\t%s\n", s, "N/A"); err != nil {
return err
}
} else {
fmt.Fprintf(signerTable, "%s\t%s\n", s, signerActor)
if _, err := fmt.Fprintf(signerTable, "%s\t%s\n", s, signerActor); err != nil {
return err
}
}
}
if err := signerTable.Flush(); err != nil {
Expand All @@ -297,7 +319,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 All @@ -308,7 +332,9 @@ 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")
if _, err := fmt.Fprintf(w, "ID\tState\tApprovals\tTo\tValue\tMethod\tParams\n"); err != nil {
return err
}
for _, txid := range txids {
tx := pending[txid]
target := tx.To.String()
Expand All @@ -320,9 +346,13 @@ 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)
if _, err := 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); err != nil {
return err
}
} 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)
if _, err := 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); err != nil {
return err
}
}
} else {
method := consensus.NewActorRegistry().Methods[targAct.Code][tx.Method] // TODO: use remote map
Expand All @@ -341,7 +371,9 @@ 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)
if _, err := 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); err != nil {
return err
}
}
}
if err := w.Flush(); err != nil {
Expand Down Expand Up @@ -923,8 +955,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
Loading
Loading