diff --git a/webapp/backend/pkg/web/server.go b/webapp/backend/pkg/web/server.go index 3339a25..af993e3 100644 --- a/webapp/backend/pkg/web/server.go +++ b/webapp/backend/pkg/web/server.go @@ -2,7 +2,9 @@ package web import ( "fmt" + "github.com/analogj/go-util/utils" "github.com/analogj/scrutiny/webapp/backend/pkg/config" + "github.com/analogj/scrutiny/webapp/backend/pkg/errors" "github.com/analogj/scrutiny/webapp/backend/pkg/web/handler" "github.com/analogj/scrutiny/webapp/backend/pkg/web/middleware" "github.com/gin-gonic/gin" @@ -10,6 +12,7 @@ import ( "io" "net/http" "os" + "path/filepath" ) type AppEngine struct { @@ -77,6 +80,13 @@ func (ae *AppEngine) Start() error { logger.SetOutput(io.MultiWriter(os.Stderr, logFile)) } + //check if the database parent directory exists, fail here rather than in a handler. + if !utils.FileExists(filepath.Dir(ae.Config.GetString("web.database.location"))) { + return errors.ConfigValidationError(fmt.Sprintf( + "Database parent directory does not exist. Please check path (%s)", + filepath.Dir(ae.Config.GetString("web.database.location")))) + } + r := ae.Setup(logger) return r.Run(fmt.Sprintf("%s:%s", ae.Config.GetString("web.listen.host"), ae.Config.GetString("web.listen.port")))