charmbracelet/gum · error

could not render file: %w

Error message

could not render file: %w

What it means

Gum table wraps the error from os.Open(o.File) with 'could not render file'. It means the CSV file passed with --file could not be opened — typically it doesn't exist, the path is wrong, or permission is denied.

Source

Thrown at table/command.go:29

	"charm.land/gum/v2/internal/stdin"
	"charm.land/gum/v2/internal/timeout"
	"charm.land/gum/v2/internal/tty"
	"charm.land/gum/v2/style"
	"charm.land/lipgloss/v2"
	ltable "charm.land/lipgloss/v2/table"
	"golang.org/x/text/encoding"
	"golang.org/x/text/encoding/unicode"
	"golang.org/x/text/transform"
)

// Run provides a shell script interface for rendering tabular data (CSV).
func (o Options) Run() error {
	var input *os.File
	if o.File != "" {
		var err error
		input, err = os.Open(o.File)
		if err != nil {
			return fmt.Errorf("could not render file: %w", err)
		}
	} else {
		if stdin.IsEmpty() {
			return fmt.Errorf("no data provided")
		}
		input = os.Stdin
	}
	defer input.Close() //nolint: errcheck

	transformer := unicode.BOMOverride(encoding.Nop.NewDecoder())
	reader := csv.NewReader(transform.NewReader(input, transformer))
	reader.LazyQuotes = o.LazyQuotes
	reader.FieldsPerRecord = o.FieldsPerRecord
	separatorRunes := []rune(o.Separator)
	if len(separatorRunes) != 1 {
		return fmt.Errorf("separator must be single character")
	}
	reader.Comma = separatorRunes[0]

View on GitHub (pinned to 4d089f9550)

Solutions

  1. Verify the file exists: ls -l <path>.
  2. Quote/unquote correctly so the shell expands ~ and $VARS: use unquoted ~/data.csv.
  3. Check read permissions on the file and its directories.
  4. Use an absolute path or verify the current working directory.
  5. Pipe data via stdin instead: `cat data.csv | gum table`.

Example fix

// before
gum table --file "~/data.csv"
// after
gum table --file ~/data.csv
# or absolute path
gum table --file /home/user/data.csv
Defensive patterns

Strategy: validation

Validate before calling

f=${FILE:-data.csv}
if [ ! -r "$f" ]; then echo "cannot read $f" >&2; exit 1; fi
gum table --file "$f"

Try / catch

if ! gum table --file "$f" 2>err.log; then echo "table failed: $(cat err.log)" >&2; fi

Prevention

When it happens

Trigger: `gum table --file path/to.csv` where the file is missing, misspelled, in a non-readable directory, or path expansion (~, $VAR) was not performed by the shell (quoted).

Common situations: Typos in file paths; using '~' inside quotes so it isn't expanded; running with a different working directory than expected; insufficient read permissions.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of charmbracelet/gum@4d089f9550 (2026-08-31). Data as JSON: /api/errors/84f3d5dae7890b7d. Report an issue: GitHub.