diff --git a/error.go b/error.go index 1785017..8107477 100644 --- a/error.go +++ b/error.go @@ -8,4 +8,6 @@ import "errors" var ( errDBNotConfigured = errors.New("Database connection string or database type were not set") errUnsupportedDBType = errors.New("DBTYPE can only be one of postgres or sqlite3") + errDBConnFailed = errors.New("Failed to open a connection to the database") + errImportFailed = errors.New("Import of local breach data failed") ) diff --git a/run.go b/run.go index 59b1a50..c3e1780 100644 --- a/run.go +++ b/run.go @@ -25,6 +25,7 @@ import ( "git.dotya.ml/mirre-mt/pcmt/config" "git.dotya.ml/mirre-mt/pcmt/ent" moddb "git.dotya.ml/mirre-mt/pcmt/modules/db" + "git.dotya.ml/mirre-mt/pcmt/modules/localbreach" "git.dotya.ml/mirre-mt/pcmt/slogging" ) @@ -160,10 +161,15 @@ func run() error { //nolint:gocognit db, err := ent.Open(setting.DbType(), setting.DbConnstring()) if err != nil { if doingImport { - log.Error("import not possible") + log.Error("Import was not possible", "error", err) + fmt.Fprintf(os.Stdout, "\033[31m✗\033[0m Import was not possible due to an error: %q\n", err) + + return errImportFailed } - return fmt.Errorf("failed to open a connection to database: %v", err) + log.Errorf("Error while connecting to DB: %q", err) + + return errDBConnFailed } defer db.Close() @@ -179,6 +185,19 @@ func run() error { //nolint:gocognit setting.SetDbIsSetUp(true) + // don't load the app, return early. + if doingImport { + lb, err := localbreach.Load(*importFlag) + if err != nil { + return err + } + + log.Infof("Import succeeded: %+v", lb) + fmt.Fprint(os.Stdout, "\033[32m🗸\033[0m Import succeeded \n") + + return nil + } + a := &app.App{} if err = a.Init(setting, slogger, db); err != nil {