flipped-aurora/gin-vue-admin · error
sqlite config invalid
Error message
sqlite config invalid
What it means
SqliteInitHandler.WriteConfig writes the SQLite init settings back to config.yaml (DbType="sqlite", rotated JWT signing key). It type-asserts the context value "config" to config.Sqlite and returns "sqlite config invalid" if the assertion fails, i.e. the context was not produced by this handler's EnsureDB. (The doc comment still says "mysql回写配置" — a stale copy-paste; the code is sqlite.)
Source
Thrown at server/service/system/sys_initdb_sqlite.go:28
"path/filepath"
"github.com/flipped-aurora/gin-vue-admin/server/config"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
"github.com/flipped-aurora/gin-vue-admin/server/utils"
)
type SqliteInitHandler struct{}
func NewSqliteInitHandler() *SqliteInitHandler {
return &SqliteInitHandler{}
}
// WriteConfig mysql回写配置
func (h SqliteInitHandler) WriteConfig(ctx context.Context) error {
c, ok := ctx.Value("config").(config.Sqlite)
if !ok {
return errors.New("sqlite config invalid")
}
global.GVA_CONFIG.System.DbType = "sqlite"
global.GVA_CONFIG.Sqlite = c
global.GVA_CONFIG.JWT.SigningKey = uuid.New().String()
cs := utils.StructToMap(global.GVA_CONFIG)
for k, v := range cs {
global.GVA_VP.Set(k, v)
}
global.GVA_ACTIVE_DBNAME = &c.Dbname
return global.GVA_VP.WriteConfig()
}
// EnsureDB 创建数据库并初始化 sqlite
func (h SqliteInitHandler) EnsureDB(ctx context.Context, conf *request.InitDB) (next context.Context, err error) {
if s, ok := ctx.Value("dbtype").(string); !ok || s != "sqlite" {
return ctx, ErrDBTypeMismatch
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Feed WriteConfig the context returned by SqliteInitHandler.EnsureDB, which stores conf.ToSqliteConfig() under key "config".
- Run the standard InitDBService.InitDB with DBType="sqlite" instead of hand-wiring handlers.
- Ensure no other handler replaced the "config" value in the context.
- Manually: ctx = context.WithValue(ctx, "config", conf.ToSqliteConfig()) before calling.
Example fix
// before ctx, _ = mysqlHandler.EnsureDB(ctx, &conf) err = sqliteHandler.WriteConfig(ctx) // -> sqlite config invalid // after ctx, _ = sqliteHandler.EnsureDB(ctx, &conf) err = sqliteHandler.WriteConfig(ctx)
Defensive patterns
Strategy: type-guard
Validate before calling
if _, ok := ctx.Value("config").(config.Sqlite); !ok {
return errors.New("sqlite config missing in context")
} Type guard
func hasSqliteConfig(ctx context.Context) bool {
_, ok := ctx.Value("config").(config.Sqlite)
return ok
} Try / catch
err := handler.WriteConfig(ctx)
if err != nil && err.Error() == "sqlite config invalid" {
// ctx not produced by SqliteInitHandler.EnsureDB; rerun EnsureDB first
} Prevention
- Only feed WriteConfig the context from SqliteInitHandler.EnsureDB.
- Don't overwrite the "config" key with another DB's struct.
- Prefer InitDBService.InitDB with DBType="sqlite".
- Test the EnsureDB -> WriteConfig sequence for sqlite.
When it happens
Trigger: Calling SqliteInitHandler.WriteConfig(ctx) where ctx's "config" value is absent or is another DB's config struct (Mysql/Pgsql/Mssql) rather than config.Sqlite.
Common situations: Mixing handlers in a custom init flow; invoking WriteConfig directly in tests without EnsureDB; refactors that change what EnsureDB stores under "config".
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/bbcbf419a9f80cd7.
Report an issue: GitHub.