Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion auth/service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func (database *ServiceProvider) Register(app foundation.Application) {

ormFacade := app.MakeOrm()
if ormFacade == nil {
return nil, errors.OrmFacadeNotSet.SetModule(errors.ModuleAuth)
// The Orm module will print the error message, so it's safe to return nil.
return nil, nil
}

ctx, ok := parameters["ctx"].(http.Context)
Expand Down
2 changes: 1 addition & 1 deletion database/gorm/dialector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func getDialectors(configs []database.FullConfig) ([]gorm.Dialector, error) {
var dialector gorm.Dialector
dsn := db.Dsn(config)
if dsn == "" {
return nil, errors.OrmFailedToGenerateDNS.Args(config.Connection)
return nil, errors.OrmFailedToGenerateDNS
}

switch config.Driver {
Expand Down
2 changes: 1 addition & 1 deletion database/gorm/dialector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestGetDialectors(t *testing.T) {
Connection: "postgres",
},
},
expectError: errors.OrmFailedToGenerateDNS.Args("postgres"),
expectError: errors.OrmFailedToGenerateDNS,
},
{
name: "Happy path - mysql",
Expand Down
2 changes: 1 addition & 1 deletion database/migration/sql_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func getMigrator(configBuilder *databasedb.ConfigBuilder, table string) (*migrat
writeConfig := writeConfigs[0]
dsn := databasedb.Dsn(writeConfigs[0])
if dsn == "" {
return nil, errors.OrmFailedToGenerateDNS.Args(writeConfig.Connection)
return nil, errors.OrmFailedToGenerateDNS
}

var (
Expand Down
12 changes: 10 additions & 2 deletions database/service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
databaseschema "github.com/goravel/framework/database/schema"
databaseseeder "github.com/goravel/framework/database/seeder"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support/color"
)

type ServiceProvider struct {
Expand All @@ -32,9 +33,15 @@ func (r *ServiceProvider) Register(app foundation.Application) {
}

connection := config.GetString("database.default")
if connection == "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use doesn't want to use the Orm module, return nil directly.

return nil, nil
}

orm, err := databaseorm.BuildOrm(ctx, config, connection, log, app.Refresh)
if err != nil {
return nil, errors.OrmInitConnection.Args(connection, err).SetModule(errors.ModuleOrm)
color.Warningln(errors.OrmInitConnection.Args(connection, err).SetModule(errors.ModuleOrm))

return nil, nil
}

return orm, nil
Expand All @@ -52,7 +59,8 @@ func (r *ServiceProvider) Register(app foundation.Application) {

orm := app.MakeOrm()
if orm == nil {
return nil, errors.OrmFacadeNotSet.SetModule(errors.ModuleSchema)
// The Orm module will print the error message, so it's safe to return an empty schema.
return &databaseschema.Schema{}, nil
}

return databaseschema.NewSchema(config, log, orm, nil), nil
Expand Down
2 changes: 1 addition & 1 deletion errors/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var (

OrmDatabaseConfigNotFound = New("not found database configuration")
OrmDriverNotSupported = New("invalid driver: %s, only support mysql, postgres, sqlite and sqlserver")
OrmFailedToGenerateDNS = New("failed to generate DSN for connection: %s")
OrmFailedToGenerateDNS = New("failed to generate DSN, please check the database configuration")
OrmFactoryMissingAttributes = New("failed to get raw attributes")
OrmFactoryMissingMethod = New("%s does not find factory method")
OrmInitConnection = New("init %s connection error: %v")
Expand Down
9 changes: 9 additions & 0 deletions foundation/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (c *Container) MakeAuth(ctx contractshttp.Context) contractsauth.Auth {
color.Errorln(err)
return nil
}
if instance == nil {
return nil
}

return instance.(contractsauth.Auth)
}
Expand Down Expand Up @@ -214,6 +217,9 @@ func (c *Container) MakeOrm() contractsorm.Orm {
color.Errorln(err)
return nil
}
if instance == nil {
return nil
}

return instance.(contractsorm.Orm)
}
Expand Down Expand Up @@ -264,6 +270,9 @@ func (c *Container) MakeSchema() contractsmigration.Schema {
color.Errorln(err)
return nil
}
if instance == nil {
return nil
}

return instance.(contractsmigration.Schema)
}
Expand Down
10 changes: 9 additions & 1 deletion support/color/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package color
import (
"bytes"
"io"
"os"

"github.com/pterm/pterm"

Expand Down Expand Up @@ -38,7 +39,14 @@ const (
)

var (
info = pterm.Info
info = pterm.PrefixPrinter{
MessageStyle: &pterm.ThemeDefault.DefaultText,
Prefix: pterm.Prefix{
Style: &pterm.Style{pterm.FgBlack, pterm.BgLightWhite},
Text: " INFO ",
},
Writer: os.Stdout,
}
Comment on lines +42 to +49
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

warning = pterm.Warning
err = pterm.Error
debug = pterm.Debug
Expand Down
Loading