{"record":{"id":"bd22ef4959133b24","repo":"charmbracelet/crush","slug":"config-not-loaded","errorCode":null,"errorMessage":"config not loaded","messagePattern":"config not loaded","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/init.go","lineNumber":31,"sourceCode":"const (\n\tInitFlagFilename = \"init\"\n)\n\ntype ProjectInitFlag struct {\n\tInitialized bool `json:\"initialized\"`\n}\n\nfunc Init(workingDir, dataDir string, debug bool) (*ConfigStore, error) {\n\tstore, err := Load(workingDir, dataDir, debug)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn store, nil\n}\n\nfunc ProjectNeedsInitialization(store *ConfigStore) (bool, error) {\n\tif store == nil {\n\t\treturn false, fmt.Errorf(\"config not loaded\")\n\t}\n\n\tcfg := store.Config()\n\tflagFilePath := filepath.Join(cfg.Options.DataDirectory, InitFlagFilename)\n\n\t_, err := os.Stat(flagFilePath)\n\tif err == nil {\n\t\treturn false, nil\n\t}\n\n\tif !os.IsNotExist(err) {\n\t\treturn false, fmt.Errorf(\"failed to check init flag file: %w\", err)\n\t}\n\n\tsomeContextFileExists, err := contextPathsExist(store.WorkingDir())\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to check for context files: %w\", err)\n\t}","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/config/init.go#L13-L49","documentation":"Returned by ProjectNeedsInitialization when the passed *ConfigStore is nil. The nil store means the config was never loaded, so the function cannot locate the data directory to check the init flag file.","triggerScenarios":"Calling config.ProjectNeedsInitialization(nil), typically after a failed/short-circuited config.Load whose result was nil but was used anyway.","commonSituations":"Ignoring the error from config.Load and passing its nil store onward; calling initialization checks before any config exists; error-handling paths that forget to return early.","solutions":["Ensure config.Load succeeded and returned a non-nil *ConfigStore before calling ProjectNeedsInitialization.","Check and handle the error returned by config.Load instead of using its nil result.","Guard call sites with an explicit nil check on the store."],"exampleFix":"// before\nneedsInit, _ := config.ProjectNeedsInitialization(store)\n// after\nif store == nil {\n\treturn fmt.Errorf(\"config must be loaded before init check\")\n}\nneedsInit, err := config.ProjectNeedsInitialization(store)","handlingStrategy":"validation","validationCode":"if store == nil {\n\treturn errors.New(\"config store is nil: load config first\")\n}","typeGuard":"func storeLoaded(s *config.ConfigStore) bool { return s != nil }","tryCatchPattern":"needsInit, err := config.ProjectNeedsInitialization(store)\nif err != nil {\n\tif err.Error() == \"config not loaded\" {\n\t\t// run config.Load first\n\t}\n\treturn err\n}","preventionTips":["Always check the error from config.Load before using its store.","Centralize config loading in one init step and pass the store down.","Fail fast on nil store rather than propagating it."],"tags":["config","nil-check","initialization"],"backgroundTag":"config-not-loaded","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}