{"record":{"id":"e16b6c11b3c9b48a","repo":"plandex-ai/plandex","slug":"error-getting-default-plan-config-v","errorCode":null,"errorMessage":"error getting default plan config: %v","messagePattern":"error getting default plan config: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/plan_config_helpers.go","lineNumber":47,"sourceCode":"\t`\n\n\t_, err := Conn.Exec(query, config, planId)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error storing plan config: %v\", err)\n\t}\n\n\treturn nil\n}\n\nfunc GetDefaultPlanConfig(userId string) (*shared.PlanConfig, error) {\n\tquery := \"SELECT default_plan_config FROM users WHERE id = $1\"\n\n\tvar config shared.PlanConfig\n\terr := Conn.Get(&config, query, userId)\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting default plan config: %v\", err)\n\t}\n\n\treturn &config, nil\n}\n\nfunc StoreDefaultPlanConfig(userId string, config *shared.PlanConfig, tx *sqlx.Tx) error {\n\tquery := `\n\t\tUPDATE users SET default_plan_config = $1 WHERE id = $2\n\t`\n\n\t_, err := tx.Exec(query, config, userId)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error storing default plan config: %v\", err)\n\t}\n\n\treturn nil\n}","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/plan_config_helpers.go#L29-L65","documentation":"GetDefaultPlanConfig wraps a failure of Conn.Get(&config, \"SELECT default_plan_config FROM users WHERE id = $1\", userId) with this message. sqlx Get expects exactly one row, so a userId with no users row (sql.ErrNoRows) also produces this error, alongside connection and scan failures.","triggerScenarios":"Called from LoadContexts, UpdateContexts, GetDefaultPlanConfigHandler, or CreatePlan with a userId absent from the users table, a broken DB connection, or a default_plan_config value that fails to scan into shared.PlanConfig.","commonSituations":"User account deleted or id mismatched while a session still references it; fresh environment where the user row was never created; corrupted default_plan_config JSON; Postgres unavailable.","solutions":["Check the wrapped cause: 'no rows in result set' means the userId is unknown — validate the user session/account exists first","If scanning fails, inspect users.default_plan_config for malformed JSON and repair or reset it","For connection errors, verify DATABASE_URL and Postgres health, then retry","Consider falling back to a zero-value PlanConfig when the user has no row, depending on desired behavior"],"exampleFix":"// before\nconfig, err := GetDefaultPlanConfig(userId)\nif err != nil { return err }\n// after: treat missing user config as empty default\nconfig, err := GetDefaultPlanConfig(userId)\nif err != nil {\n    if strings.Contains(err.Error(), \"no rows in result set\") {\n        config = &shared.PlanConfig{}\n    } else {\n        return err\n    }\n}","handlingStrategy":"fallback","validationCode":"var exists bool\nerr := Conn.Get(&exists, \"SELECT EXISTS(SELECT 1 FROM users WHERE id=$1)\", userId)\nif err != nil || !exists {\n    // invalid session/user — handle before querying the config\n}","typeGuard":null,"tryCatchPattern":"config, err := GetDefaultPlanConfig(userId)\nif err != nil {\n    if strings.Contains(err.Error(), \"no rows in result set\") {\n        config = &shared.PlanConfig{} // fallback default\n    } else {\n        return nil, err\n    }\n}","preventionTips":["Verify the user id from a trusted session, never client-supplied alone","Use NOT NULL / DEFAULT '{}' for users.default_plan_config to avoid null-scan surprises","Validate stored config JSON on write so reads never hit scan errors","Probe DB health at startup to distinguish infra errors from data errors"],"tags":["database","postgres","not-found","sqlx","go"],"backgroundTag":"record-not-found","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}