-
Notifications
You must be signed in to change notification settings - Fork 240
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
Add lastError function #3654
base: development
Are you sure you want to change the base?
Add lastError function #3654
Conversation
Sets lastError, so use it for constructing all errors except control transferring errors like return, continue, etc.
Also set position for suppressed errors
In particular, we previously constructed the error message when returning with it (when stopIfError/returnIfError true). Now we always construct it (so it gets saved to lastError), but only return with it in those cases.
Also remove a bunch of cruft in the file error-messages.m2
e(x,p1,h1) | ||
f(x,p1,h1) | ||
g(x,p1,h1) | ||
assert((last try 1/0 else lastError()) == "division by zero") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you planning on replacing the manual tests above with automatic versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
I did something similar on my dev branch. I'll compare the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not directly related, but do you know what these two lines are for:
Lines 307 to 308 in 3fc8759
export errorMessageClass := newtypeof(basicListClass); | |
export missingMethodClass := newtypeof(errorMessageClass); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea! They don't appeared to be used anywhere.
here are AFAICT the main differences I find between your implementation and mine:
|
One of the big goals was to find out if there was an error without actually raising one, e.g., That being said, @MichaelABurr has some code updating it during
That was our original idea, but we didn't realize it was possible. Most of the global variables like this (e.g., Is your code live on Macaulay2Web? Or just in a branch somewhere? |
good point. maybe I'm wrong about updating it when it's printed, as you said, the main goal is to test the error message with |
the relevant commit seems to be 74e022a |
I still think having a global variable is marginally simpler than a function. |
This returns a sequence containing the location and message string for the last error (at least most of the time, e.g., not for syntax errors).
The eventual goal is to use this in the MPI package (see #2129) for handling errors gracefully, e.g., doing something like
try x else lastError()
.