charmbracelet/glow · error

unable to read from reader: %w

Error message

unable to read from reader: %w

What it means

executeCLI reads the entire source (URL response body, opened file, or stdin) into memory with io.ReadAll(src.reader). This error means the read itself failed mid-stream: a connection reset while downloading remote content, a filesystem I/O error while reading a local file, or a revoked/truncated source. It is distinct from open errors - the source was obtained successfully, then reading it failed.

Source

Thrown at main.go:277

	}

	return nil
}

func executeArg(cmd *cobra.Command, arg string, w io.Writer) error {
	// create an io.Reader from the markdown source in cli-args
	src, err := sourceFromArg(arg)
	if err != nil {
		return err
	}
	defer src.reader.Close() //nolint:errcheck
	return executeCLI(cmd, src, w)
}

func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
	b, err := io.ReadAll(src.reader)
	if err != nil {
		return fmt.Errorf("unable to read from reader: %w", err)
	}

	b = utils.RemoveFrontmatter(b)

	// render
	var baseURL string
	u, err := url.ParseRequestURI(src.URL)
	if err == nil {
		u.Path = filepath.Dir(u.Path)
		baseURL = u.String() + "/"
	}

	isCode := !utils.IsMarkdownFile(src.URL)

	// initialize glamour
	r, err := glamour.NewTermRenderer(
		utils.GlamourStyle(style, isCode),
		glamour.WithWordWrap(int(width)), //nolint:gosec

View on GitHub (pinned to e3970c813d)

Solutions

  1. Retry the fetch - mid-body resets are usually transient
  2. Verify the source directly: curl the URL, or cat the local file to completion
  3. For local files on odd storage, check dmesg / mount health if reads keep failing
  4. For very large documents, render a smaller file to rule out memory exhaustion
Defensive patterns

Strategy: try-catch

Type guard

func isNetReadErr(err error) bool {
	var opErr *net.OpError
	return errors.As(err, &opErr)
}

Try / catch

b, err := io.ReadAll(src.reader)
if err != nil {
	if isNetReadErr(err) {
		// transient reset mid-body: re-open the source and read again
	} else {
		return fmt.Errorf("unable to read from reader: %w", err)
	}
}

Prevention

When it happens

Trigger: Remote server drops the connection mid-body; a local file sits on failing storage (EIO); the file is truncated or removed between open and read; reading from a pipe fd returns an error rather than EOF.

Common situations: Unstable networks fetching large READMEs, removable media removed mid-run, NFS/filesystem faults, huge files exceeding available memory.

Related errors


AI-assisted analysis of charmbracelet/glow@e3970c813d (2026-08-15). Data as JSON: /api/errors/08fe48123b354204. Report an issue: GitHub.