Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/uu/tsort/src/tsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use string_interner::StringInterner;
use string_interner::backend::BucketBackend;
use thiserror::Error;
use uucore::display::Quotable;
use uucore::error::{UError, UResult, USimpleError};
use uucore::error::{FromIo, UError, UResult, USimpleError};
use uucore::{format_usage, show, translate};

// short types for switching interning behavior on the fly.
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
return Err(TsortError::IsDir(input.to_string_lossy().to_string()).into());
}
}
let file = File::open(input)?;
let file = File::open(input).map_err_context(|| input.maybe_quote().to_string())?;
// advise the OS we will access the data sequentially if possible
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
let _ = rustix::fs::fadvise(&file, 0, None, rustix::fs::Advice::Sequential);
Expand Down
8 changes: 8 additions & 0 deletions tests/by-util/test_tsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,11 @@ fn test_only_one_input_file() {
.fails_with_code(1)
.stderr_only(TSORT_EXTRA_OPERAND_ERROR);
}

#[test]
fn test_nonexistent_file_error_includes_filename() {
new_ucmd!()
.arg("nosuchfile.txt")
.fails_with_code(1)
.stderr_only("tsort: nosuchfile.txt: No such file or directory\n");
}