-
Notifications
You must be signed in to change notification settings - Fork 165
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
Make error output use the same stream consistently #2529
Make error output use the same stream consistently #2529
Conversation
I just realized that Where and WHERE also should take a stream ad their first argument. But OnBreak is bound to Where. I'll also have to adjust calls to OnBreak then. |
OnBreak is documented to have only one argument though. I will define it as function() Where("errout"); end; |
lib/error.g
Outdated
@@ -204,7 +204,7 @@ BIND_GLOBAL("ErrorInner", | |||
if printThisStatement then | |||
if context <> GetBottomLVars() then | |||
PrintTo("*errout*"," in\n \c"); | |||
PRINT_CURRENT_STATEMENT(context); | |||
PRINT_CURRENT_STATEMENT("*errout*", context); | |||
Print("\c"); |
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.
Shouldn't this also be printed to *errout*
?
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.
Ofc. Thanks :)
And Where is also documented. I'll let them take a stream ad an optional first argument then. |
bedb0f1
to
8fab742
Compare
I actually don't think it's that important or useful for |
lib/error.g
Outdated
PRINT_CURRENT_STATEMENT(context); | ||
Print("\c"); | ||
PRINT_CURRENT_STATEMENT("*errout*", context); | ||
PrintFto("*errout*", "\c"); |
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.
Typo: PrintFto
src/error.c
Outdated
int openedOutput = 1; | ||
if ((IsStringConv(stream) && !OpenOutput(CSTR_STRING(stream))) || | ||
(!IS_STRING(stream) && !OpenOutputStream(stream))) { | ||
Pr("Can't open output stream\n", 0L, 0L); |
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.
Can't -> Cannot
@fingolfin I will introduce a global variable that tells Where, WHERE, and ErrorInner where to send all error output. |
8fab742
to
fa4d1ce
Compare
src/error.c
Outdated
Pr("Can not open output stream\n", 0L, 0L); | ||
openedOutput = 0; | ||
} | ||
|
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.
So when you did not manage to open the output, you still print an error message to the current output and set a flag?
Did you try just raising an error using ErrorMayQuit
?
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.
I thought calling other Error functions may lead to an infinite loop. ErrorMayQuit
itself also calls ErrorInner
.
I will change it to print to *errout*
- or quit if that also fails - to prevent that GAP could silently write to e.g. a file when encountering errors.
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.
Is there a better option than quitting if I also can't open errout?
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.
Ah, I can tell ErrorMayQuit to not go into a break loop. I'll try that.
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.
If you can't open errout, I would just exit. For example, the C level function PRINT_OR_APPEND_TO, which is used for printing to streams, if it tries to print to errout and fails, just exits GAP.
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.
gah, the two arguments to ErrorMayQuit
are forwarded to Pr
. I thought they were arguments that toggle the behaviour. :/
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.
Thanks for the hint.
lib/error.g
Outdated
# If an interactive SHELL is started by a break loop it still listens | ||
# and prints to "*errin*" and "*errout*" respectively. | ||
GAP_ERROR_STREAM := "*errout*"; | ||
|
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.
We are currently talking about #1815, which could potentially replace this variable with another one (or remove the need for it); I think having it around right now would make it easy to search and replace, so not much of a problem.
lib/error.g
Outdated
PRINT_CURRENT_STATEMENT(context); | ||
Print("\c"); | ||
PrintTo("*errout*"," called from \n"); | ||
PrintTo(GAP_ERROR_STREAM, " in\n \c"); |
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.
strictly speaking the \c
is not necessary anymore now.
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.
I wanted to refactor all of ErrorInner once this PR is merged. I will remove "all" of them then.
fa4d1ce
to
297ddfc
Compare
Codecov Report
@@ Coverage Diff @@
## master #2529 +/- ##
==========================================
- Coverage 74.6% 74.6% -0.01%
==========================================
Files 481 481
Lines 242402 242409 +7
==========================================
+ Hits 180855 180859 +4
- Misses 61547 61550 +3
|
d1c6456
to
e987cfb
Compare
src/error.c
Outdated
} else { | ||
int ret = fputs("gap: panic, can not open *errout*!\n", stderr); | ||
// If that failed, try printing to stdout | ||
if(ret == EOF) { |
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.
Please run clang-format
resp. git clang-format
on this PR.
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.
Done
e987cfb
to
e2700e9
Compare
As long as #1815 is not merged, |
I just realized that one travis test-suite is failing.. |
e2700e9
to
0ff91a5
Compare
I fixed the bug. I forgot to do |
src/error.c
Outdated
{ | ||
if (context == STATE(BottomLVars)) | ||
return 0; |
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.
How about leaving this check here at the start, before trying to open the output stream? That seems simpler than opening the stream, then perform a trivial check, then close it again. Am I missing something?
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.
That's a lot better. I'll adjust it.
49ffb8c
to
58f12d2
Compare
I also got rid of all flush characters in ErrorInner. These are unnecessary because now we always print to the same stream. |
src/error.c
Outdated
} | ||
else { | ||
int ret = fputs("gap: panic, can not open *errout*!\n", stderr); | ||
/* If that failed, try printing to stdout */ |
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.
Hmm, why do this? Is there a specific problem case you have in mind there? Why would printing to stderr fail? And if it fails, would printing to stdout still work? And, are we really that desperate to print this message?
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.
I didn't have any specific situation in mind. I thought a fallback option for when errout can't be openend would make sense. As to why first try stderr and then stdout: I saw similar code in PRINT_OR_APPEND_TO
in streams.c
and thought "better be safe than sorry".
Should I change this to just print to stderr and exit directly?
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.
I changed this to be consistent with basically any other "GAP panic".
bb45e33
to
03583e3
Compare
src/error.c
Outdated
} | ||
else { | ||
fputs("gap: panic, can not open *errout*!\n", stderr); | ||
SyExit(1); |
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.
These two lines could be changed to use the new Panic
helper function. But that's not very important.
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.
Done.
src/error.c
Outdated
if ((IsStringConv(stream) && !OpenOutput(CSTR_STRING(stream))) || | ||
(!IS_STRING(stream) && !OpenOutputStream(stream))) { | ||
if (OpenOutput("*errout*")) { | ||
Pr("PRINT_CURRENT_STATEMENT: can not open error stream\n", 0, 0); |
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.
Hmm, maybe "could not" or "failed to" instead of "can not? Same in the message a few lines below?
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.
Sounds good.
03583e3
to
d071366
Compare
- ErrorInner, Where, and WHERE consistently print their output to "*errout*" - Get rid of now unnecessary flush character \c in ErrorInner - PRINT_CURRENT_STATEMENT now takes a stream as additional input. - Adjust its tests accordingly.
d071366
to
4e59eff
Compare
to print functions