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 4b484ee
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 32 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
18 changes: 12 additions & 6 deletions cli/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,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 @@ -272,7 +273,9 @@ var msigInspectCmd = &cli.Command{
return err
}
fmt.Fprintf(cctx.App.Writer, "Threshold: %d / %d\n", threshold, len(signers))
fmt.Fprintln(cctx.App.Writer, "Signers:")
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")
Expand All @@ -297,7 +300,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 +928,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
26 changes: 14 additions & 12 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
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
7 changes: 5 additions & 2 deletions node/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ func FromReader(reader io.Reader, def interface{}, opts ...LoadCfgOpt) (interfac
}
for _, d := range movedFields {
if md.IsDefined(d.Field...) {
fmt.Fprintf(
if _, err := fmt.Fprintf(
warningOut,
"WARNING: Use of deprecated configuration option '%s' will be removed in a future release, use '%s' instead\n",
strings.Join(d.Field, "."),
strings.Join(d.NewField, "."))
strings.Join(d.NewField, "."),
); err != nil {
return nil, err
}
if !md.IsDefined(d.NewField...) {
// new value isn't set but old is, we should move what the user set there
if err := moveFieldValue(cfg, d.Field, d.NewField); err != nil {
Expand Down

0 comments on commit 4b484ee

Please sign in to comment.