{"record":{"id":"fd3ba285878e4b6c","repo":"micro/go-micro","slug":"flags-not-parsed","errorCode":null,"errorMessage":"flags not parsed","messagePattern":"flags not parsed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/source/flag/flag.go","lineNumber":19,"sourceCode":"package flag\n\nimport (\n\t\"errors\"\n\t\"flag\"\n\t\"strings\"\n\t\"time\"\n\n\t\"dario.cat/mergo\"\n\t\"go-micro.dev/v6/config/source\"\n)\n\ntype flagsrc struct {\n\topts source.Options\n}\n\nfunc (fs *flagsrc) Read() (*source.ChangeSet, error) {\n\tif !flag.Parsed() {\n\t\treturn nil, errors.New(\"flags not parsed\")\n\t}\n\n\tvar changes map[string]interface{}\n\n\tvisitFn := func(f *flag.Flag) {\n\t\tn := strings.ToLower(f.Name)\n\t\tkeys := strings.FieldsFunc(n, split)\n\t\treverse(keys)\n\n\t\ttmp := make(map[string]interface{})\n\t\tfor i, k := range keys {\n\t\t\tif i == 0 {\n\t\t\t\ttmp[k] = f.Value\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\ttmp = map[string]interface{}{k: tmp}\n\t\t}","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/config/source/flag/flag.go#L1-L37","documentation":"The flag config source reads values from the standard library flag package, but it can only do so after flag.Parse() has been called. Read() throws this error when the flags have not yet been parsed, because there are no values to expose.","triggerScenarios":"Building a config source from flags and calling Read() (directly or via config.Load) before flag.Parse() ran in main; skipping flag.Parse entirely in a service that loads config early.","commonSituations":"Config loading hoisted before argument parsing in an init/main ordering refactor; tests constructing the flag source without simulating parsed flags; using a library that defers parsing while your code reads config first.","solutions":["Call flag.Parse() in main before initializing the config stack that includes the flag source.","Reorder startup: parse flags first, then load config so Read() sees parsed values.","If flags are managed by another package, invoke that package's Parse entrypoint before reading config.","In tests, call flag.Parse() with a prepared flag.CommandLine set or use flag.CommandLine.Parse(args)."],"exampleFix":"// before\nfunc main() {\n    cfg, _ := config.Load() // flag source errors: flags not parsed\n    flag.Parse()\n}\n// after\nfunc main() {\n    flag.Parse()\n    cfg, _ := config.Load()\n}","handlingStrategy":"validation","validationCode":"if !flag.Parsed() {\n    flag.Parse()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call flag.Parse() as the first statement of main","Never load flag-based config before argument parsing","In tests, parse a controlled flag.CommandLine before Read()"],"tags":["cli","flags","configuration","lifecycle"],"backgroundTag":"flags-not-parsed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}