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

[Feature]: better error message from run() #853

Open
1 task done
kellijohnson-NOAA opened this issue Jul 20, 2023 · 6 comments
Open
1 task done

[Feature]: better error message from run() #853

kellijohnson-NOAA opened this issue Jul 20, 2023 · 6 comments
Assignees
Labels
enhancement low priority A low-priority item that does NOT have to be worked on

Comments

@kellijohnson-NOAA
Copy link
Contributor

Describe the feature request.

When using r4ss::run() where the executable passed to the exe argument was a non-viable executable, that I obviously did not know was 🗑️, I got a non-intuitive/cryptic error message back from system2(), not one of the beautiful options documented in the return section of the documentation

r4ss/R/run.R

Lines 18 to 20 in 92821e7

#' @return Returns one of five messages:
#' "ran model", "model run failed", "unknown run status", "not a
#' directory", or "contained Report.sso".

Turns out, when a non-viable executable is passed to exe, system2() returns

error in `system2()`:
! 'CreateProcess' failed to run
'c:\github\PFMC-A~1\SABLEF~1\models\2023\base\base\test.exe`

I was confused because of all the tildes in the path. So, I thought maybe I had the path wrong; but, I checked the path multiple times and the file did exist. I just did not know that the executable did not work. So, I was thinking we could write a test that searches through messages captured via try/catch for the tilde and give users our own message that if the file does in fact exist that they should check that it actually works.

Describe alternatives you have considered

Not add anything to r4ss and see if we can get system2 to return a better warning.

Statistical validity, if applicable

No response

Describe if this is needed for a management application

No response

Additional context

No response

Code of Conduct

@kellijohnson-NOAA kellijohnson-NOAA added enhancement low priority A low-priority item that does NOT have to be worked on labels Jul 20, 2023
@iantaylor-NOAA
Copy link
Contributor

@kellijohnson-NOAA, I'm happy to work on this, but I don't know how to make a 🗑️ executable like you had to replicate the issue. Can you send me something?

@e-perl-NOAA
Copy link
Contributor

e-perl-NOAA commented Oct 11, 2023

I can work on this with you Ian too. And agreed, a 🗑️ executable would be helpful to reproduce and create the right error.

@kellijohnson-NOAA
Copy link
Contributor Author

Sorry it has taken me so long to reply. I did not create the executable that didn't work for me, instead I downloaded it via r4ss::get_ss3_exe() and I am pretty sure that the executable was for a different operating system than Windows and I was on a Windows machine. I was able to recreate the error message by downloading the linux executable and trying to use it from within R after I changed the name to have the .exe extension. I got a pop up warning message when I used system() as well as a console message and I just got the console message when I used system2() which is used by r4ss::run(). The console message was the exact same message that I reported above. Let me know if you need any more information, and I will try to respond quicker next time 😁

iantaylor-NOAA added a commit that referenced this issue Oct 17, 2023
iantaylor-NOAA added a commit that referenced this issue Oct 17, 2023
@iantaylor-NOAA
Copy link
Contributor

@kellijohnson-NOAA, thanks for the additional info and no worries on the timeline, especially since you labeled this issue "low priority".
This problem is harder than it looks.
Running a linux executable in Windows produced a similar error for me.

I just added a new message in 6f0026b which now causes the output to look like

r4ss::run("C:/SS/SSv3.30.22betas/SSv3.30.22beta_Oct11/", exe = "ss_linux", show_in_console = TRUE)
Executable found in directory C:/SS/SSv3.30.22betas/SSv3.30.22beta_Oct11/
Changing working directory to C:/SS/SSv3.30.22betas/SSv3.30.22beta_Oct11/ and running model using the command: ss_linux.exe 
Error in r4ss::run("C:/SS/SSv3.30.22betas/SSv3.30.22beta_Oct11/", exe = "ss_linux",  : 
  There is a problem with the executable, perhaps due to mismatch with the operating system.
In addition: Warning message:
In system2(command = command, args = extras, stdout = ifelse(show_in_console,  :       
  'CreateProcess' failed to run 'C:\SS\SSV330~4.22B\SSV330~4.22B\ss_linux.exe '        

However, that doesn't work when you have show_in_console = FALSE

Adding more complex error checking via tryCatch() in 81aa8db seems to have gotten things working for both TRUE or FALSE input to show_in_console.

However, now it is not correctly passing the results to return() at the end of the function.

I'm worried that the risk of making things overly complex in order to produce a useful error message for this rare case of a bad executable will cause more common errors to get missed.

@kellijohnson-NOAA and @e-gugliotti-NOAA feel free to suggest things I'm not thinking of.

@kellijohnson-NOAA
Copy link
Contributor Author

Maybe the alternative is to put information in the documentation of run(), perhaps in the Details section, that explains what we are seeing here rather than trying to code it? I am also fine with just having this issue closed because the information is searchable and when someone gets the warning maybe they would search the issues of r4ss and find it?

@e-perl-NOAA
Copy link
Contributor

Yes, plus the get_ss3_exe() function tells you which exe it downloaded so if that function downloaded an exe for the wrong OS, the OS that it did download the exe for would be stated in the messages for that function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement low priority A low-priority item that does NOT have to be worked on
Projects
None yet
Development

No branches or pull requests

3 participants