{"record":{"id":"a1ffa6cba64bbe83","repo":"gastownhall/beads","slug":"applying-hook-migration-w","errorCode":null,"errorMessage":"applying hook migration: %w","messagePattern":"applying hook migration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor_fix.go","lineNumber":458,"sourceCode":"\t\treturn nil\n\t}\n\n\tfor _, migration := range pending {\n\t\tswitch migration.Name {\n\t\tcase \"hooks\":\n\t\t\tplan, err := doctor.PlanHookMigration(path)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"building hook migration plan: %w\", err)\n\t\t\t}\n\n\t\t\texecPlan := buildHookMigrationExecutionPlan(plan)\n\t\t\tif len(execPlan.BlockingErrors) > 0 {\n\t\t\t\treturn fmt.Errorf(\"hook migration is blocked:\\n- %s\", strings.Join(execPlan.BlockingErrors, \"\\n- \"))\n\t\t\t}\n\n\t\t\tsummary, err := applyHookMigrationExecution(execPlan)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"applying hook migration: %w\", err)\n\t\t\t}\n\n\t\t\tfmt.Printf(\n\t\t\t\t\"  Hook migration applied: %d hook(s) written, %d artifact(s) retired, %d artifact(s) skipped\\n\",\n\t\t\t\tsummary.WrittenHookCount,\n\t\t\t\tsummary.RetiredCount,\n\t\t\t\tsummary.SkippedCount,\n\t\t\t)\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"no automatic fix available for pending migration %q\", migration.Name)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":440,"sourceCodeEnd":474,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor_fix.go#L440-L474","documentation":"fixPendingMigrations wraps failures from applyHookMigrationExecution when actually writing hooks or retiring artifacts. The %w cause describes the concrete failure (write permission, disk error, etc.). It occurs after the plan passed blocking-error checks.","triggerScenarios":"`bd fix` with a pending hooks migration where applyHookMigrationExecution fails mid-apply: hook file not writable, git dir changed between plan and apply, or filesystem error writing hook content.","commonSituations":"Read-only .git/hooks (root-owned files after sudo usage), disk full, or hooks directory deleted/replaced after planning (TOCTOU between plan and apply).","solutions":["Read the wrapped cause and fix it (usually chmod/chown .git/hooks or free disk space)","Ensure .git/hooks is writable by the current user: `ls -la .git/hooks`","Re-run `bd fix` — planning and application are re-done atomically per migration","If partially applied, run `bd doctor` to see remaining pending migrations and re-fix"],"exampleFix":"// before\nsudo bd fix   # hooks written as root\n// after\nbd fix        # run as the repo owner so .git/hooks stays writable","handlingStrategy":"try-catch","validationCode":"info, err := os.Stat(hooksDir)\nif err != nil || !info.IsDir() || unix.Access(hooksDir, unix.W_OK) != nil {\n  return fmt.Errorf(\".git/hooks not writable\")\n}","typeGuard":null,"tryCatchPattern":"if err := fixPendingMigrations(pending, path); err != nil {\n  if strings.Contains(err.Error(), \"applying hook migration\") {\n    // check permissions/disk, then re-run: apply is re-planned safely\n    return err\n  }\n}","preventionTips":["Run bd as the repo owner, not via sudo","Ensure adequate disk space before migrations","Avoid mutating .git/hooks between planning and applying (no parallel hook tools during bd fix)","Re-run `bd doctor` after any failure to detect partial application"],"tags":["migration","hooks","doctor","filesystem"],"backgroundTag":"hook-migration-apply-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}