Skip to content

std.fs.read_file silently returns "" for a missing/unreadable path — errors indistinguishable from an empty file #909

Closed

Description

@ehartford

Repro

use std.fs
use std.builtins.print_i64
fn main:
    let text = read_file("/definitely/not/a/real/path.txt")
    print_i64(text.len())   // prints 0, rc=0 — no error anywhere

Why it bit

During the #795 directive sweep, a shell quoting slip passed one
newline-joined mega-argument as the file path. read_file returned ""
for the bogus path, the migration script matched nothing, and the only
symptom was "migrated 0 files" — the failure was completely silent. A
missing input file and an empty input file are indistinguishable.

This is the repo's own "no silent fallbacks" doctrine violated at the
stdlib surface: the API swallows the error class users most need to see
(typo'd path, permissions, TOCTOU deletion).

Expected

Either read_file(path: &str) -> Result[str, FsError] (callers use ?
— the with-y shape), or at minimum a loud panic on missing paths with a
separate read_file_opt/exists for probe-style callers. Signature
change touches all current callers (tools/, build/, tests) — small
sweep, mechanical.

Same review should cover write_file's error surface (returns i32 rc —
at least visible, but unchecked at most call sites).

Activity

  1. added a commit that references this issue on Sep 4, 2026
    08f87b6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions