Skip to content

Commit

Permalink
Use new Errno in yash_semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
magicant committed Apr 7, 2024
1 parent 8fdc121 commit 8c24b79
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion yash-semantics/src/command/compound_command/subshell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub async fn execute(env: &mut Env, body: Rc<List>, location: &Location) -> Resu
print_error(
env,
"cannot start subshell".into(),
errno.desc().into(),
errno.to_string().into(),
location,
)
.await;
Expand Down
2 changes: 1 addition & 1 deletion yash-semantics/src/command/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async fn execute_async(env: &mut Env, and_or: &Rc<AndOrList>, async_flag: &Locat
print_error(
env,
"cannot start a subshell to run an asynchronous command".into(),
errno.desc().into(),
errno.to_string().into(),
async_flag,
)
.await;
Expand Down
26 changes: 7 additions & 19 deletions yash-semantics/src/command/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,8 @@ async fn execute_job_controlled_pipeline(
}
Err(errno) => {
// TODO print error location using yash_env::io::print_error
env.system
.print_error(&format!(
"cannot start a subshell in the pipeline: {}\n",
errno.desc()
))
.await;
let message = format!("cannot start a subshell in the pipeline: {}\n", errno);
env.system.print_error(&message).await;
Break(Divert::Interrupt(Some(ExitStatus::NOEXEC)))
}
}
Expand Down Expand Up @@ -197,12 +193,8 @@ async fn shift_or_fail(env: &mut Env, pipes: &mut PipeSet, has_next: bool) -> Re
Ok(()) => Continue(()),
Err(errno) => {
// TODO print error location using yash_env::io::print_error
env.system
.print_error(&format!(
"cannot connect pipes in the pipeline: {}\n",
errno.desc()
))
.await;
let message = format!("cannot connect pipes in the pipeline: {}\n", errno);
env.system.print_error(&message).await;
Break(Divert::Interrupt(Some(ExitStatus::NOEXEC)))
}
}
Expand All @@ -217,12 +209,8 @@ async fn connect_pipe_and_execute_command(
Ok(()) => (),
Err(errno) => {
// TODO print error location using yash_env::io::print_error
env.system
.print_error(&format!(
"cannot connect pipes in the pipeline: {}\n",
errno.desc()
))
.await;
let message = format!("cannot connect pipes in the pipeline: {}\n", errno);
env.system.print_error(&message).await;
return Break(Divert::Interrupt(Some(ExitStatus::NOEXEC)));
}
}
Expand All @@ -244,7 +232,7 @@ async fn pid_or_fail(
env.system
.print_error(&format!(
"cannot start a subshell in the pipeline: {}\n",
errno.desc()
errno
))
.await;
Break(Divert::Interrupt(Some(ExitStatus::NOEXEC)))
Expand Down
2 changes: 1 addition & 1 deletion yash-semantics/src/command/simple_command/absent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub async fn execute_absent_target(
print_error(
env,
"cannot start subshell to perform redirection".into(),
errno.desc().into(),
errno.to_string().into(),
&first_redir_location,
)
.await;
Expand Down
4 changes: 2 additions & 2 deletions yash-semantics/src/command/simple_command/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub async fn start_external_utility_in_subshell_and_wait(
print_error(
env,
format!("cannot execute external utility {:?}", name.value).into(),
errno.desc().into(),
errno.to_string().into(),
&name.origin,
)
.await;
Expand Down Expand Up @@ -191,7 +191,7 @@ pub async fn replace_current_process(
print_error(
env,
format!("cannot execute external utility {path:?}").into(),
errno.desc().into(),
errno.to_string().into(),
&location,
)
.await;
Expand Down
2 changes: 1 addition & 1 deletion yash-semantics/src/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl ErrorCause {
// TODO Localize
use ErrorCause::*;
match self {
CommandSubstError(e) => e.desc().into(),
CommandSubstError(e) => e.to_string().into(),
ArithError(e) => e.to_string().into(),
AssignReadOnly(e) => e.to_string().into(),
UnsetParameter => "unset parameter disallowed by the nounset option".into(),
Expand Down
6 changes: 3 additions & 3 deletions yash-semantics/src/redir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ impl ErrorCause {
match self {
Expansion(e) => e.label(),
NulByte(_) => "pathname should not contain a nul byte".into(),
FdNotOverwritten(_, errno) => errno.desc().into(),
FdNotOverwritten(_, errno) => errno.to_string().into(),
ReservedFd(fd) => format!("file descriptor {fd} reserved by shell").into(),
OpenFile(path, errno) => format!("{}: {}", path.to_string_lossy(), errno.desc()).into(),
OpenFile(path, errno) => format!("{}: {}", path.to_string_lossy(), errno).into(),
MalformedFd(value, error) => format!("{value}: {error}").into(),
UnreadableFd(fd) => format!("{fd}: not a readable file descriptor").into(),
UnwritableFd(fd) => format!("{fd}: not a writable file descriptor").into(),
TemporaryFileUnavailable(errno) => errno.desc().into(),
TemporaryFileUnavailable(errno) => errno.to_string().into(),
}
}
}
Expand Down

0 comments on commit 8c24b79

Please sign in to comment.