gastownhall/beads · error

error reading file: %w

Error message

error reading file: %w

What it means

After scanning lines, parseMarkdownFile checks scanner.Err() and wraps any read failure as "error reading file: <os error>". Unlike open errors, this fires mid-scan — the file opened fine but reading its contents hit an I/O problem.

Source

Thrown at cmd/bd/markdown.go:300

		// Check for H2 (new issue)
		if matches := h2Regex.FindStringSubmatch(line); matches != nil {
			state.handleH2Header(matches)
			continue
		}

		// Check for H3 (section within issue)
		if matches := h3Regex.FindStringSubmatch(line); matches != nil {
			state.handleH3Header(matches)
			continue
		}

		// Regular content line
		state.handleContentLine(line)
	}

	if err := scanner.Err(); err != nil {
		return nil, fmt.Errorf("error reading file: %w", err)
	}

	return state.finalize()
}

// createIssuesFromMarkdown creates every issue in a markdown file as ONE act,
// through issueops.BatchCreator. It parses the file, lints it, builds one
// request and prints what came back; the proxied route builds the SAME request.
func createIssuesFromMarkdown(ctx context.Context, in createInput) error {
	templates, err := parseMarkdownFile(in.markdownFile)
	if err != nil {
		return HandleError("parsing markdown file: %v", err)
	}
	if len(templates) == 0 {
		return HandleError("no issues found in markdown file")
	}
	if store == nil {
		return HandleErrorWithHint("database not initialized", diagHint())

View on GitHub (pinned to 71377f2769)

Solutions

  1. Re-run the import — transient I/O errors often clear
  2. Copy the file to local disk first and import the local copy
  3. Check dmesg/mount status for disk or NFS problems if reproducible
  4. Stop concurrent writers so the file is not mutated during the scan

Example fix

// before
parseMarkdownFile("/mnt/nfs/issues.md")   // flaky NFS
// after
cp /mnt/nfs/issues.md /tmp/issues.md && parseMarkdownFile("/tmp/issues.md")
Defensive patterns

Strategy: retry

Validate before calling

// ensure stable local copy before import
cp /network/issues.md /tmp/issues.md

Try / catch

err := runImport(path)
for i := 0; err != nil && strings.Contains(err.Error(), "error reading file") && i < 2; i++ {
	time.Sleep(time.Second)
	err = runImport(path)
}

Prevention

When it happens

Trigger: The bufio scanner hits an I/O error while reading (disk error, file truncated/changed on a network mount, device removed), after os.Open succeeded.

Common situations: Unstable network filesystems (NFS/SMB dropouts); file being rewritten concurrently by another process; failing disk or removable media pulled mid-read.

Related errors


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