jayjun / rambo

Run your command. Send input. Get output.
MIT License
199 stars 21 forks source link

Is this output expected? #3

Open thbar opened 4 years ago

thbar commented 4 years ago

I'm trying out Rambo to monitor long-running Ruby processes. Thank you for your work!

If I run something like:

Rambo.run("incorrect_command", log: true)

I will get {:error, "rambo exited with 0"} as the output.

But if I run this from the command line, instead I will get -bash: incorrect_command: command not found.

I found the error message somewhat surprising (even if I understand where it comes from).

Should it instead capture & return the output of bash?

Thanks!

jayjun commented 4 years ago

exited with 0 is definitely surprising to me. I tried and got 101 as expected.

iex(1)> Rambo.run("incorrect_command", log: true)
thread 'main' panicked at 'failed to spawn child: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:203:21
                                                                                                                                           note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
                                      {:error, "rambo exited with 101"}

Either way, Rambo does not use Bash or any shell. It forks and executes the command directly, so there’s no command not found generated.

Currently Rambo crashes by design because a wrong command should be a programming error. Would a friendlier message help?

jayjun commented 4 years ago

To clarify, the Rambo shim crashes by design but Rambo inside Elixir still returns gracefully with {:error, "rambo exited with 101"}. So two other options are,

  1. Crash inside Elixir too with Rambo.CommandNotFoundError.
  2. Return with a better error message like {:error, "rambo: command not found"}.

Adding Rambo.run! to support both does not seem right. A wrong command should be fatal and surfaced as soon as possible, so I’m leaning to option 1.