gastownhall/beads · error

reading source content for %s from %s: %w

Error message

reading source content for %s from %s: %w

What it means

renderMigratedHookContent builds the new hook body from a base source: for hook-file/old/backup source kinds it reads the existing file at op.SourcePath. This error wraps any os.ReadFile failure (missing file, permissions) with the hook name and source path so the user knows which sidecar could not be read.

Source

Thrown at cmd/bd/migrate_hooks_apply.go:316

			HookName: op.HookName,
			Path:     op.HookPath,
			Content:  rendered,
		})
	}

	return prepared, nil
}

func renderMigratedHookContent(op hookMigrationWriteOp) ([]byte, error) {
	var baseContent string

	switch op.SourceKind {
	case hookMigrationWriteFromTemplate:
		baseContent = ""
	case hookMigrationWriteFromHookFile, hookMigrationWriteFromOld, hookMigrationWriteFromBackup:
		content, err := os.ReadFile(op.SourcePath) // #nosec G304 -- source paths come from migration planner + known sidecar suffixes
		if err != nil {
			return nil, fmt.Errorf("reading source content for %s from %s: %w", op.HookName, op.SourcePath, err)
		}
		baseContent = string(content)
	default:
		return nil, fmt.Errorf("unknown source kind %q for %s", op.SourceKind, op.HookName)
	}

	baseContent = strings.ReplaceAll(baseContent, "\r\n", "\n")
	baseContent = ensureHookShebang(baseContent)

	content := injectHookSection(baseContent, generateHookSection(op.HookName))
	content = strings.ReplaceAll(content, "\r\n", "\n")
	if !strings.HasSuffix(content, "\n") {
		content += "\n"
	}

	return []byte(content), nil
}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Verify the source file exists: `ls -la` the path named in the error
  2. Restore the sidecar from backup/SCM, or re-run the migration plan so a fresh source is chosen
  3. If the sidecar is intentionally gone, delete it from the plan and migrate from template instead
  4. Fix read permissions on the source file
Defensive patterns

Strategy: validation

Validate before calling

// confirm sidecar sources exist before apply
for (const op of plan.RetireOps.concat(plan.WriteOps)) {
  if (op.SourceKind !== 'template' && !fs.existsSync(op.SourcePath)) throw new Error('missing source: '+op.SourcePath);
}

Try / catch

if err := apply(...); err != nil && strings.Contains(err.Error(), "reading source content for") {
    // restore the sidecar or regenerate the plan, then retry
}

Prevention

When it happens

Trigger: prepareHookMigrationPlanning chose hookMigrationWriteFromHookFile/Old/Backup, but the referenced file does not exist or is unreadable when content is rendered.

Common situations: Sidecar file (.old/.backup) deleted by the user or a cleanup tool between plan and apply; stale plan referencing a sidecar that no longer exists; permission-restricted hook files.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/641278543cfd7b55. Report an issue: GitHub.