Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output when execution fails #12

Open
filhodanuvem opened this issue Apr 2, 2023 · 6 comments
Open

Output when execution fails #12

filhodanuvem opened this issue Apr 2, 2023 · 6 comments

Comments

@filhodanuvem
Copy link

I think it would be helpful to have a way to see/get the output of failure executions, from what I see we don't have it because the log.fatal here exits the run.
What do you think?

@javaducky
Copy link
Contributor

Hi @filhodanuvem! Thank you for noticing that...it's not much help when the command silently fails.

@diegombeltran
Copy link

+1 to this feature!

@fczuardi
Copy link

What would be the best return for the exec.command in this case? Log the error and return an empty string? Log the error and return the exit status as a string? Or return the same string that is being printed in the log.fatal (but without interrupting the main execution?

@fczuardi
Copy link

Out of curiosity, I went looking for the forks of this project and it seems that changing this is a popular motivator forforking.

Some replace this log.Fatal with a log.Print, like main...eznd-go:xk6-exec:main and and main...fcurella:xk6-exec:main while other even put it under an option for backwards compatibility: 60c5a41

It would be nice to have one of the patches landed on the main project. Is there any reason not to do it? What is missing? The pull requests?

@filhodanuvem
Copy link
Author

filhodanuvem commented Nov 5, 2023

In my opinion it is just about creating the pull request, time has passed and I didn't do it. Go for it @fczuardi if that unblocks you in any way.
The best approach for me would be changing the method Command to return also an error, the caller would be responsible to panic it or not but I understand that this might generates a big PR.

xk6-exec/exec.go

Lines 49 to 58 in 997ee1b

func (*EXEC) Command(name string, args []string, option CommandOptions) string {
cmd := exec.Command(name, args...)
if option.Dir != "" {
cmd.Dir = option.Dir
}
out, err := cmd.Output()
if err != nil {
log.Fatal(err.Error() + " on command: " + name + " " + strings.Join(args, " "))
}
return string(out)

@romaia
Copy link

romaia commented Mar 30, 2024

So, this was bothering me as well, so I created PR #20 that allows to specify an option fatalError: false to disable the current behavior. When ommited, it will keep failing for backwards compatibility.

I also took the oportunity to add support for an env option that will set environment variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants