NOAA-PMEL / Ferret

The Ferret program from NOAA/PMEL
https://ferret.pmel.noaa.gov/Ferret/
The Unlicense
55 stars 21 forks source link

Idea: include script-name, traceback with error messages #1966

Closed AnsleyManke closed 4 years ago

AnsleyManke commented 4 years ago

A thread started by Marco van Hulten 1/27/20 asks about including the script name and line number when reporting an error, which would be helpful for debugging when there are number of scripts which call each other.

Currently the error handler reports the error name, a general error message for the type of error, and possibly text that was provided by the internal routine that detected the error. It also shows the command that was trying to run (as it appears after parsing). We could add the script-name here. To report the line-number from the script we'd have to add more data structures, but it should be possible.

The discussion goes on to suggest giving an option to report the tree of calls and the command that last ran in each. Un-parsed commands are not saved once parsed. It would not be hard to save the last-parsed command in its original form but not the whole history of un-parsed or parsed commands. Once commands successfully run they are not kept. I do not see a way to recover the last command run before each script call, but the stack of calling scripts would be straightforward.

@AndrewWittenberg

AnsleyManke commented 4 years ago

This is done. Adding a line that includes the script call as it was made, including any arguments to the script.

For example, here's a call to "GO polymark" where the number of color levels specified is larger than the allowed number:

yes? LET xpts = 180 + 50*COS(2*3.14*I[I=1:50]/60)
yes? LET ypts = 15  + 20*SIN(2*3.14*I[I=1:50]/60)
yes? LET sst = 25 - ypts + RANDN(ypts)
yes? plot/vs xpts,ypts
yes? GO polymark POLYGON/KEY/LEV=300 xpts,ypts,sst,star
 **ERROR: invalid command: "300": Number of contour levels must be between 1 and 250
POLYGON/KEY/LEV=300/coord_ax=Z  PLMxpoly+PLMxpolymark, PLMypoly+PLMypolymark, PLMpolydata
Command file, command group, or REPEAT execution aborted
Running script: polymark POLYGON/KEY/LEV=300 xpts,ypts,sst,star

The new line comes after the error messages generated by Ferret/PyFerret.

If there are error messages created by scripts, it so happens that the new "Running script" line comes before the ones generated by the script say in a "query" argument-checking command. So a bad argument to the "go land" script does this:

yes? go land thick dummy
Command file, command group, or REPEAT execution aborted
Running script: land thick dummy
 **ERROR: argument 2 can be "basemap", "overlay", or "fast"
AndrewWittenberg commented 4 years ago

Fantastic, thanks!

One small suggestion would to change "Running script:" to "Executed by script:". This might be a little less confusing when it comes at the end of the output, since "running" might make a user think that something is still running.

AnsleyManke commented 4 years ago

-- I see what you mean. Or maybe just "error in script". It might also be nice to set off the script call so it's more obvious. Also I think I'll add the word "GO " which isn't inside Ferret at that moment but would make things clearer.

Command file, command group, or REPEAT execution aborted
Executed by script:  *** go polymark POLYGON/KEY/LEV=300 xpts,ypts,sst,star ***

or

Command file, command group, or REPEAT execution aborted
Script call was:   *** go polymark POLYGON/KEY/LEV=300 xpts,ypts,sst,star ***