Skip to content

Commit

Permalink
fix(cosmosanalysis): DeepFindImplementation() should fallback to `a…
Browse files Browse the repository at this point in the history
…pp/app.go`
  • Loading branch information
ilgooz committed Mar 18, 2022
1 parent 0c3d9a6 commit 8baf7d8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions starport/pkg/cosmosanalysis/cosmosanalysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
package cosmosanalysis

import (
"errors"
"fmt"
"go/ast"
"go/parser"
"go/token"
"os"
"path/filepath"

"github.com/pkg/errors"
"golang.org/x/mod/modfile"
)

const (
cosmosModulePath = "github.com/cosmos/cosmos-sdk"
tendermintModulePath = "github.com/tendermint/tendermint"
appFileName = "app.go"
defaultAppFilePath = "app/" + appFileName
)

var appImplementation = []string{
Expand Down Expand Up @@ -195,7 +196,7 @@ func FindAppFilePath(chainRoot string) (path string, err error) {

numFound := len(found)
if numFound == 0 {
return "", errors.New("app file not found")
return "", errors.New("app.go file cannot be found")
}

if numFound == 1 {
Expand All @@ -206,7 +207,8 @@ func FindAppFilePath(chainRoot string) (path string, err error) {
for _, p := range found {
if filepath.Base(p) == appFileName {
if appFilePath != "" {
return "", errors.New("multiple app.go files found")
// multiple app.go found, fallback to app/app.go
return getDefaultAppFile(chainRoot)
}

appFilePath = p
Expand All @@ -217,5 +219,12 @@ func FindAppFilePath(chainRoot string) (path string, err error) {
return appFilePath, nil
}

return "", errors.New("multiple app files found, but no app.go file")
return getDefaultAppFile(chainRoot)
}

// getDefaultAppFile returns the default app.go file path for a chain.
func getDefaultAppFile(chainRoot string) (string, error) {
path := filepath.Join(chainRoot, defaultAppFilePath)
_, err := os.Stat(path)
return path, errors.Wrap(err, "cannot locate your app.go")
}

0 comments on commit 8baf7d8

Please sign in to comment.