{"record":{"id":"c8b159587bdc5d3a","repo":"flipped-aurora/gin-vue-admin","slug":"s-c8b159","errorCode":null,"errorMessage":"未找到 %s 表初始化数据","messagePattern":"未找到 (.+?) 表初始化数据","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/source/system/dictionary_detail.go","lineNumber":48,"sourceCode":"\tdb, ok := ctx.Value(\"db\").(*gorm.DB)\n\tif !ok {\n\t\treturn false\n\t}\n\treturn db.Migrator().HasTable(&sysModel.SysDictionaryDetail{})\n}\n\nfunc (i *initDictDetail) InitializerName() string {\n\treturn sysModel.SysDictionaryDetail{}.TableName()\n}\n\nfunc (i *initDictDetail) InitializeData(ctx context.Context) (context.Context, error) {\n\tdb, ok := ctx.Value(\"db\").(*gorm.DB)\n\tif !ok {\n\t\treturn ctx, system.ErrMissingDBContext\n\t}\n\tdicts, ok := ctx.Value(new(initDict).InitializerName()).([]sysModel.SysDictionary)\n\tif !ok {\n\t\treturn ctx, errors.Wrap(system.ErrMissingDependentContext,\n\t\t\tfmt.Sprintf(\"未找到 %s 表初始化数据\", sysModel.SysDictionary{}.TableName()))\n\t}\n\tTrue := true\n\tdicts[0].SysDictionaryDetails = []sysModel.SysDictionaryDetail{\n\t\t{Label: \"男\", Value: \"1\", Status: &True, Sort: 1},\n\t\t{Label: \"女\", Value: \"2\", Status: &True, Sort: 2},\n\t}\n\n\tdicts[1].SysDictionaryDetails = []sysModel.SysDictionaryDetail{\n\t\t{Label: \"smallint\", Value: \"1\", Status: &True, Extend: \"mysql\", Sort: 1},\n\t\t{Label: \"mediumint\", Value: \"2\", Status: &True, Extend: \"mysql\", Sort: 2},\n\t\t{Label: \"int\", Value: \"3\", Status: &True, Extend: \"mysql\", Sort: 3},\n\t\t{Label: \"bigint\", Value: \"4\", Status: &True, Extend: \"mysql\", Sort: 4},\n\t\t{Label: \"int2\", Value: \"5\", Status: &True, Extend: \"pgsql\", Sort: 5},\n\t\t{Label: \"int4\", Value: \"6\", Status: &True, Extend: \"pgsql\", Sort: 6},\n\t\t{Label: \"int6\", Value: \"7\", Status: &True, Extend: \"pgsql\", Sort: 7},\n\t\t{Label: \"int8\", Value: \"8\", Status: &True, Extend: \"pgsql\", Sort: 8},\n\t}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/source/system/dictionary_detail.go#L30-L66","documentation":"Thrown by the sys_dictionary_details initializer when the shared init context does not contain the SysDictionary seed data produced by initDict under its InitializerName key. This is a dependency-ordering guard: dictionary details must attach to dictionaries seeded earlier. The wrapped sentinel is system.ErrMissingDependentContext.","triggerScenarios":"Calling initDictDetail.InitializeData(ctx) with a ctx that never passed through initDict.InitializeData, or the earlier initializer stored a non-[]sysModel.SysDictionary value / failed and stored nothing under new(initDict).InitializerName().","commonSituations":"Reordering the initializer registration list so the detail initializer runs before the dictionary initializer; reusing a fresh context.Value(\"db\")-only context for a single initializer in tests; an earlier dictionary init error swallowed so its result was never placed in the context.","solutions":["Ensure initDict runs (and succeeds) before initDictDetail in the initializer registration/execution order","Pass the same ctx through the whole initializer chain instead of constructing a new one per initializer","Check the return error of the dictionary initializer before calling the detail initializer; fix that first (see sys_dictionaries 表数据初始化失败)","In custom/test harnesses, populate ctx with context.WithValue(ctx, new(initDict).InitializerName(), []sysModel.SysDictionary{...}) before calling"],"exampleFix":"// before: detail init on a fresh context missing dictionary data\nctx, _ = initDictDetail{}.InitializeData(context.WithValue(ctx, \"db\", db))\n// after: run dependent initializers in order on the shared context\nctx, err = initDict{}.InitializeData(ctx)\nif err != nil { return err }\nctx, err = initDictDetail{}.InitializeData(ctx)","handlingStrategy":"validation","validationCode":"dicts, ok := ctx.Value(new(initDict).InitializerName()).([]sysModel.SysDictionary)\nif !ok || len(dicts) == 0 {\n    return errors.New(\"run initDict initializer before initDictDetail\")\n}","typeGuard":"func dictionariesInCtx(ctx context.Context) ([]sysModel.SysDictionary, bool) {\n    dicts, ok := ctx.Value(new(initDict).InitializerName()).([]sysModel.SysDictionary)\n    return dicts, ok && len(dicts) > 0\n}","tryCatchPattern":"ctx, err = initDictDetail{}.InitializeData(ctx)\nif errors.Is(errors.Cause(err), system.ErrMissingDependentContext) {\n    return fmt.Errorf(\"初始化顺序错误: %w\", err)\n}","preventionTips":["Keep the system initializer order fixed: dependents after their dependencies","Never construct a fresh context for a single initializer; pass the shared ctx","Always check and propagate the error from each initializer before the next","Add an integration test that runs the full initializer chain in order"],"tags":["gorm","initialization","dependency-order","context"],"backgroundTag":"missing-dependent-init-context","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}