Skip to content
Merged
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 spec/std/process_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe Process do

it "raises if command could not be executed" do
# FIXME: Oddly doubled error message
expect_raises_errno(Errno::ENOENT, "execvp: No such file or directory: No such file or directory") do
Process.new("foobarbaz")
expect_raises_errno(Errno::ENOENT, %(execvp (foobarbaz "foo"): No such file or directory: No such file or directory)) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the printed command need a length restriction? If it has many arguments, then there could be some issues with the usability.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restricting the length could also have usability implications. The best solution would be to change the order and print the failed command after the libc error message. Errno doesn't support that though.

Process.new("foobarbaz", ["foo"])
end
end

Expand Down
12 changes: 11 additions & 1 deletion src/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,17 @@ class Process
argv << Pointer(UInt8).null

LibC.execvp(command, argv)
raise Errno.new("execvp")

error_message = String.build do |io|
io << "execvp ("
command.inspect_unquoted(io)
args.try &.each do |arg|
io << ' '
arg.inspect(io)
end
io << ")"
end
raise Errno.new(error_message)
end

private def self.reopen_io(src_io : IO::FileDescriptor, dst_io : IO::FileDescriptor)
Expand Down