@@ -53,45 +53,24 @@ func Database(name ...string) gdb.DB {
53
53
if v , _ := Config ().Get (ctx , configNodeKey ); ! v .IsEmpty () {
54
54
configMap = v .Map ()
55
55
}
56
+ // No configuration found, it formats and panics error.
56
57
if len (configMap ) == 0 && ! gdb .IsConfigured () {
57
58
// File configuration object checks.
58
- var (
59
- err error
60
- configFilePath string
61
- )
59
+ var err error
62
60
if fileConfig , ok := Config ().GetAdapter ().(* gcfg.AdapterFile ); ok {
63
- if configFilePath , _ = fileConfig .GetFilePath (); configFilePath == "" {
64
- var (
65
- exampleFileName = "config.example.toml"
66
- exampleConfigFilePath string
67
- )
68
- if exampleConfigFilePath , _ = fileConfig .GetFilePath (exampleFileName ); exampleConfigFilePath != "" {
69
- err = gerror .NewCodef (
70
- gcode .CodeMissingConfiguration ,
71
- `configuration file "%s" not found, but found "%s", did you miss renaming the example configuration file?` ,
72
- fileConfig .GetFileName (),
73
- exampleFileName ,
74
- )
75
- } else {
76
- err = gerror .NewCodef (
77
- gcode .CodeMissingConfiguration ,
78
- `configuration file "%s" not found, did you miss the configuration file or the misspell the configuration file name?` ,
79
- fileConfig .GetFileName (),
80
- )
81
- }
82
- if err != nil {
83
- panic (err )
84
- }
61
+ if _ , err = fileConfig .GetFilePath (); err != nil {
62
+ panic (gerror .WrapCode (gcode .CodeMissingConfiguration , err ,
63
+ `configuration not found, did you miss the configuration file or the misspell the configuration file name` ,
64
+ ))
85
65
}
86
66
}
87
67
// Panic if nothing found in Config object or in gdb configuration.
88
68
if len (configMap ) == 0 && ! gdb .IsConfigured () {
89
- err = gerror .NewCodef (
69
+ panic ( gerror .NewCodef (
90
70
gcode .CodeMissingConfiguration ,
91
- `database initialization failed: "%s" node not found, is configuration file or configuration node missing? ` ,
71
+ `database initialization failed: configuration missing for database node "%s" ` ,
92
72
consts .ConfigNodeNameDatabase ,
93
- )
94
- panic (err )
73
+ ))
95
74
}
96
75
}
97
76
0 commit comments