can1357/oh-my-pi · critical

failed to read filter definition {}: {e}

Error message

failed to read filter definition {}: {e}

What it means

pi-natives' build script generates crates/pi-natives/out/.../builtin_filters.toml at compile time by concatenating every *.toml filter definition in src/shell/minimizer/defs/. If any definition file exists in the directory listing but cannot be read to a String (permissions, decode error, vanished mid-build), the build script panics with this message, failing the cargo build with the offending path and io/UTF-8 error embedded.

Source

Thrown at crates/pi-natives/build.rs:58

		println!("cargo:rerun-if-changed={}", path.display());
		match fs::read_to_string(&path) {
			Ok(body) => {
				let filename = path
					.file_name()
					.and_then(|n| n.to_str())
					.unwrap_or("unknown");
				writeln!(concatenated, "# --- {filename} ---").expect("write to String");
				for line in body.lines() {
					let trimmed = line.trim_start();
					if trimmed.starts_with("schema_version") {
						continue;
					}
					concatenated.push_str(line);
					concatenated.push('\n');
				}
				concatenated.push('\n');
			},
			Err(e) => panic!("failed to read filter definition {}: {e}", path.display()),
		}
	}

	fs::write(&output_path, concatenated)
		.unwrap_or_else(|e| panic!("failed to write {}: {e}", output_path.display()));
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the full panic message to identify the offending path, then check its permissions (`ls -l src/shell/minimizer/defs/`) and fix with chmod/chown so the build user can read it.
  2. Verify the file is valid UTF-8 (`file` / `iconv -f utf-8 -t utf-8 <path>`); re-save or delete any binary or wrong-encoding .toml in defs/.
  3. Remove stale temp/backup files (e.g. *.toml~, editor swap files) from the defs directory and rebuild.
  4. Do a clean checkout or `git checkout -- crates/pi-natives/src/shell/minimizer/defs/` if the files were locally modified or corrupted.

Example fix

// before: unreadable definition blocks the build
$ ls -l crates/pi-natives/src/shell/minimizer/defs/
-rw------- 1 root root 240 builtin-rm.toml
// panic: failed to read filter definition .../builtin-rm.toml: Permission denied (os error 13)

// after: restore readability, then rebuild
$ sudo chmod 644 crates/pi-natives/src/shell/minimizer/defs/builtin-rm.toml
$ cargo build -p pi-natives
Defensive patterns

Strategy: validation

Validate before calling

# Run before building to catch unreadable/binary filter defs:
for f in crates/pi-natives/src/shell/minimizer/defs/*.toml; do
  test -r "$f" || { echo "unreadable: $f"; exit 1; }
  iconv -f utf-8 -t utf-8 "$f" >/dev/null || { echo "not utf-8: $f"; exit 1; }
done

Try / catch

# Build script panics abort the build; capture and triage:
if ! cargo build -p pi-natives 2>build.log; then
  grep -q 'failed to read filter definition' build.log && \
    echo "Fix/restore the listed file in src/shell/minimizer/defs/"
  exit 1
fi

Prevention

When it happens

Trigger: Running `cargo build`/`cargo test` for pi-natives when a .toml file inside src/shell/minimizer/defs/ cannot be read: unreadable file permissions, invalid UTF-8 content, or the file being deleted/replaced between fs::read_dir and fs::read_to_string.

Common situations: Cloning the repo on a filesystem that mangles permissions; an editor or tool leaving a temp/lock .toml with restrictive mode in defs/; a non-UTF-8 (binary or Latin-1) file dropped into defs/; running the build as a different user than the file owner; read-only mounts or container volume permission mismatches.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/c6761ce8dd730eb6. Report an issue: GitHub.