Skip to main content

load_text_strict

Function load_text_strict 

Source
pub fn load_text_strict(path: &Path, display: &str) -> Result<String>
Expand description

Load a path as UTF-8 text under the Strict sole-path policy (#1894).

Use for explicit single-file mutators and sole-path reads (CLI/MCP/tx/api).

KindResult
TextOk(String)
BinaryErr(BinaryError)target is a binary file: {display} (error_kind: binary)
Invalid UTF-8Err(InvalidEncodingError)target is not valid UTF-8 text: {display} (error_kind: invalid_encoding)
Not a fileErr(InvalidInputError)target is not a file: {display}
IO NotFoundErr with io::Error + context failed to read {display} (is_io_not_found)
IO other (permission, …)Err(InvalidInputError)failed to read {display}: {os error}

Binary / invalid UTF-8 are distinct from argument invalid_input so hosts can recover overwrite without treating empty paths the same as content SoftSkip (#1963). Non-NotFound IO is typed so agent JSON gets error_kind: invalid_input and a single complete message that includes the OS error even when callers format with Display / to_string() (which drops anyhow cause chains). NotFound stays an IO error so [crate::exit::is_io_not_found] keeps working.

Directory walks and multi-path soft-skip must use read_text_file (or tx::read_and_probe), not this function.