Skip to content

Commit

Permalink
fix_: address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Oct 23, 2024
1 parent 7735ef9 commit cc809f9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
20 changes: 9 additions & 11 deletions cmd/lint-panics/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"go/ast"
"os"
"time"

"go.uber.org/zap"

Expand All @@ -18,7 +17,7 @@ import (
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"

gopls2 "github.com/status-im/status-go/cmd/lint-panics/gopls"
"github.com/status-im/status-go/cmd/lint-panics/gopls"
"github.com/status-im/status-go/cmd/lint-panics/utils"
)

Expand All @@ -43,15 +42,17 @@ func New(ctx context.Context, logger *zap.Logger) (*analysis.Analyzer, error) {

logger.Info("creating analyzer", zap.String("root", cfg.RootDir))

gopls := gopls2.NewGoplsClient(ctx, logger, cfg.RootDir)
processor := newAnalyzer(logger, gopls, &cfg)
goplsClient := gopls.NewGoplsClient(ctx, logger, cfg.RootDir)
processor := newAnalyzer(logger, goplsClient, &cfg)

analyzer := &analysis.Analyzer{
Name: "logpanics",
Doc: fmt.Sprintf("reports missing defer call to %s", Pattern),
Run: processor.Run,
Flags: flags,
Requires: []*analysis.Analyzer{inspect.Analyzer},
Run: func(pass *analysis.Pass) (interface{}, error) {
return processor.Run(ctx, pass)
},
}

return analyzer, nil
Expand All @@ -65,21 +66,18 @@ func newAnalyzer(logger *zap.Logger, lsp LSP, cfg *Config) *Analyzer {
}
}

func (p *Analyzer) Run(pass *analysis.Pass) (interface{}, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

func (p *Analyzer) Run(ctx context.Context, pass *analysis.Pass) (interface{}, error) {
inspected, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
if !ok {
return nil, errors.New("analyzer is not type *inspector.Inspector")

Check warning on line 72 in cmd/lint-panics/analyzer/analyzer.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/analyzer/analyzer.go#L72

Added line #L72 was not covered by tests
}

// Check if the node is a GoStmt (which represents a 'go' statement)
// Create a nodes filter for goroutines (GoStmt represents a 'go' statement)
nodeFilter := []ast.Node{
(*ast.GoStmt)(nil),
}

// Traverse the AST to find goroutines
// Inspect go statements
inspected.Preorder(nodeFilter, func(n ast.Node) {
p.ProcessNode(ctx, pass, n)
})
Expand Down
8 changes: 7 additions & 1 deletion cmd/lint-panics/analyzer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ func (c *Config) ParseFlags() (flag.FlagSet, error) {
// We parse the flags here to have `rootDir` before the call to `singlechecker.Main(analyzer)`
// For same reasons we discard the output and skip the undefined flag error.
err := flags.Parse(os.Args[1:])
if err != nil && strings.Contains(err.Error(), "flag provided but not defined") {
if err == nil {
return *flags, nil

Check warning on line 36 in cmd/lint-panics/analyzer/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/analyzer/config.go#L36

Added line #L36 was not covered by tests
}

if strings.Contains(err.Error(), "flag provided but not defined") {
err = nil
} else if strings.Contains(err.Error(), "help requested") {
err = nil

Check warning on line 42 in cmd/lint-panics/analyzer/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/analyzer/config.go#L42

Added line #L42 was not covered by tests
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/lint-panics/gopls/gopls.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewGoplsClient(ctx context.Context, logger *zap.Logger, rootDir string) *Co
panic(err)

Check warning on line 55 in cmd/lint-panics/gopls/gopls.go

View check run for this annotation

Codecov / codecov/patch

cmd/lint-panics/gopls/gopls.go#L54-L55

Added lines #L54 - L55 were not covered by tests
}

stream := jsonrpc2.NewStream(&CombinedReadWriteCloser{
stream := jsonrpc2.NewStream(&IOStream{
stdin: stdin,
stdout: stdout,
})
Expand Down
10 changes: 5 additions & 5 deletions cmd/lint-panics/gopls/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ package gopls

import "io"

// CombinedReadWriteCloser combines stdin and stdout into one interface.
type CombinedReadWriteCloser struct {
// IOStream combines stdin and stdout into one interface.
type IOStream struct {
stdin io.WriteCloser
stdout io.ReadCloser
}

// Write writes data to stdin.
func (c *CombinedReadWriteCloser) Write(p []byte) (n int, err error) {
func (c *IOStream) Write(p []byte) (n int, err error) {
return c.stdin.Write(p)
}

// Read reads data from stdout.
func (c *CombinedReadWriteCloser) Read(p []byte) (n int, err error) {
func (c *IOStream) Read(p []byte) (n int, err error) {
return c.stdout.Read(p)
}

// Close closes both stdin and stdout.
func (c *CombinedReadWriteCloser) Close() error {
func (c *IOStream) Close() error {
err1 := c.stdin.Close()
err2 := c.stdout.Close()
if err1 != nil {
Expand Down
4 changes: 2 additions & 2 deletions healthmanager/blockchain_health_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"sync"

gocommon "github.com/status-im/status-go/common"
status_common "github.com/status-im/status-go/common"
"github.com/status-im/status-go/healthmanager/aggregator"
"github.com/status-im/status-go/healthmanager/rpcstatus"
)
Expand Down Expand Up @@ -73,7 +73,7 @@ func (b *BlockchainHealthManager) RegisterProvidersHealthManager(ctx context.Con
statusCh := phm.Subscribe()
b.wg.Add(1)
go func(phm *ProvidersHealthManager, statusCh chan struct{}, providerCtx context.Context) {
defer gocommon.LogOnPanic()
defer status_common.LogOnPanic()
defer func() {
phm.Unsubscribe(statusCh)
b.wg.Done()
Expand Down
8 changes: 4 additions & 4 deletions services/wallet/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
signercore "github.com/ethereum/go-ethereum/signer/core/apitypes"
abi_spec "github.com/status-im/status-go/abi-spec"
"github.com/status-im/status-go/account"
common2 "github.com/status-im/status-go/common"
status_common "github.com/status-im/status-go/common"
statusErrors "github.com/status-im/status-go/errors"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
Expand Down Expand Up @@ -780,7 +780,7 @@ func (api *API) BuildTransactionsFromRoute(ctx context.Context, buildInputParams
log.Debug("[WalletAPI::BuildTransactionsFromRoute] builds transactions from the generated best route", "uuid", buildInputParams.Uuid)

go func() {
defer common2.LogOnPanic()
defer status_common.LogOnPanic()
api.router.StopSuggestedRoutesAsyncCalculation()

var err error
Expand Down Expand Up @@ -843,7 +843,7 @@ func (api *API) ProceedWithTransactionsSignatures(ctx context.Context, signature
func (api *API) SendRouterTransactionsWithSignatures(ctx context.Context, sendInputParams *requests.RouterSendTransactionsParams) {
log.Debug("[WalletAPI:: SendRouterTransactionsWithSignatures] sign with signatures and send")
go func() {
defer common2.LogOnPanic()
defer status_common.LogOnPanic()

var (
err error
Expand Down Expand Up @@ -930,7 +930,7 @@ func (api *API) SendRouterTransactionsWithSignatures(ctx context.Context, sendIn
chainIDs = append(chainIDs, tx.FromChain)
addresses = append(addresses, common.Address(tx.FromAddress))
go func(chainId uint64, txHash common.Hash) {
defer common2.LogOnPanic()
defer status_common.LogOnPanic()
err = api.s.transactionManager.WatchTransaction(context.Background(), chainId, txHash)
if err != nil {
return
Expand Down

0 comments on commit cc809f9

Please sign in to comment.