diff --git a/blockchains/smartchain/assets/0xc15e89f2149bcc0cbd5fb204c9e77fe878f1e9b2/info.json b/blockchains/smartchain/assets/0xc15e89f2149bCC0cBd5FB204C9e77fe878f1e9b2/info.json similarity index 100% rename from blockchains/smartchain/assets/0xc15e89f2149bcc0cbd5fb204c9e77fe878f1e9b2/info.json rename to blockchains/smartchain/assets/0xc15e89f2149bCC0cBd5FB204C9e77fe878f1e9b2/info.json diff --git a/blockchains/smartchain/assets/0xc15e89f2149bcc0cbd5fb204c9e77fe878f1e9b2/logo.png b/blockchains/smartchain/assets/0xc15e89f2149bCC0cBd5FB204C9e77fe878f1e9b2/logo.png similarity index 100% rename from blockchains/smartchain/assets/0xc15e89f2149bcc0cbd5fb204c9e77fe878f1e9b2/logo.png rename to blockchains/smartchain/assets/0xc15e89f2149bCC0cBd5FB204C9e77fe878f1e9b2/logo.png diff --git a/cmd/main.go b/cmd/main.go index ebd11e8f0..e4c05032e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -8,6 +8,7 @@ import ( "github.com/trustwallet/assets/internal/config" "github.com/trustwallet/assets/internal/file" "github.com/trustwallet/assets/internal/processor" + "github.com/trustwallet/assets/internal/report" "github.com/trustwallet/assets/internal/service" ) @@ -23,9 +24,10 @@ func main() { log.WithError(err).Fatal("Failed to load file structure.") } - fileStorage := file.NewService(paths...) - validatorsService := processor.NewService(fileStorage) - assetfsProcessor := service.NewService(fileStorage, validatorsService) + fileService := file.NewService(paths...) + validatorsService := processor.NewService(fileService) + reportService := report.NewService() + assetfsProcessor := service.NewService(fileService, validatorsService, reportService) switch script { case "checker": @@ -39,6 +41,14 @@ func main() { default: log.Info("Nothing to launch. Use --script flag to choose a script to run.") } + + reportMsg := reportService.GetReport() + + if reportService.IsFailed() { + log.Fatal(reportMsg) + } else { + log.Info(reportMsg) + } } func setup() { diff --git a/internal/file/path.go b/internal/file/path.go index bb893f8b8..6efcf02d6 100644 --- a/internal/file/path.go +++ b/internal/file/path.go @@ -1,6 +1,7 @@ package file import ( + "fmt" "os" "path/filepath" "regexp" @@ -147,7 +148,7 @@ func ReadLocalFileStructure(root string, filesToSkip []string) ([]string, error) return nil } - paths = append(paths, path) + paths = append(paths, fmt.Sprintf("./%s", path)) return nil }) diff --git a/internal/file/file.go b/internal/file/service.go similarity index 100% rename from internal/file/file.go rename to internal/file/service.go diff --git a/internal/processor/processor.go b/internal/processor/service.go similarity index 100% rename from internal/processor/processor.go rename to internal/processor/service.go diff --git a/internal/report/service.go b/internal/report/service.go new file mode 100644 index 000000000..543640ad9 --- /dev/null +++ b/internal/report/service.go @@ -0,0 +1,28 @@ +package report + +import "fmt" + +type Service struct { + errors int + totalFiles int +} + +func NewService() *Service { + return &Service{} +} + +func (s *Service) IncErrors() { + s.errors += 1 +} + +func (s *Service) IncTotalFiles() { + s.totalFiles += 1 +} + +func (s Service) IsFailed() bool { + return s.errors > 0 +} + +func (s Service) GetReport() string { + return fmt.Sprintf("Total files: %d, errors: %d", s.totalFiles, s.errors) +} diff --git a/internal/service/service.go b/internal/service/service.go index 37ed63784..d09cbd67e 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -4,6 +4,7 @@ import ( "github.com/trustwallet/assets-go-libs/validation" "github.com/trustwallet/assets/internal/file" "github.com/trustwallet/assets/internal/processor" + "github.com/trustwallet/assets/internal/report" log "github.com/sirupsen/logrus" ) @@ -11,12 +12,14 @@ import ( type Service struct { fileService *file.Service processorService *processor.Service + reportService *report.Service } -func NewService(fs *file.Service, cs *processor.Service) *Service { +func NewService(fs *file.Service, cs *processor.Service, rs *report.Service) *Service { return &Service{ fileService: fs, processorService: cs, + reportService: rs, } } @@ -24,6 +27,7 @@ func (s *Service) RunJob(paths []string, job func(*file.AssetFile)) { for _, path := range paths { f := s.fileService.GetAssetFile(path) job(f) + s.reportService.IncTotalFiles() } } @@ -32,8 +36,7 @@ func (s *Service) Check(f *file.AssetFile) { if validator != nil { if err := validator.Run(f); err != nil { - // TODO: somehow return an error from Check if there are any errors. - HandleError(err, f, validator.Name) + s.handleError(err, f, validator.Name) } } } @@ -43,7 +46,7 @@ func (s *Service) Fix(f *file.AssetFile) { for _, fixer := range fixers { if err := fixer.Run(f); err != nil { - HandleError(err, f, fixer.Name) + s.handleError(err, f, fixer.Name) } } } @@ -67,7 +70,7 @@ func (s *Service) runUpdaters(updaters []processor.Updater) { } } -func HandleError(err error, info *file.AssetFile, valName string) { +func (s *Service) handleError(err error, info *file.AssetFile, valName string) { errors := UnwrapComposite(err) for _, err := range errors { @@ -78,6 +81,8 @@ func HandleError(err error, info *file.AssetFile, valName string) { "path": info.Path(), "validation": valName, }).Error(err) + + s.reportService.IncErrors() } }