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

Make error output use the same stream consistently #2529

Merged

Conversation

ssiccha
Copy link
Contributor

@ssiccha ssiccha commented Jun 7, 2018

  • PRINT_CURRENT_STATEMENT now takes a stream as additional input.
  • Adjust its tests accordingly.
  • Make ErrorInner, Where, and WHERE consistently pass "errout"
    to print functions

@ssiccha ssiccha requested review from fingolfin and markuspf June 7, 2018 11:11
@ssiccha
Copy link
Contributor Author

ssiccha commented Jun 7, 2018

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.

@ssiccha
Copy link
Contributor Author

ssiccha commented Jun 7, 2018

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");
Copy link
Member

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*?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ofc. Thanks :)

@ssiccha
Copy link
Contributor Author

ssiccha commented Jun 7, 2018

And Where is also documented. I'll let them take a stream ad an optional first argument then.

@ssiccha ssiccha force-pushed the ss/make-print-curr-stat-redirectable branch from bedb0f1 to 8fab742 Compare June 7, 2018 13:30
@fingolfin
Copy link
Member

I actually don't think it's that important or useful for Where to have a stream argument. Do you really need that for jupyter?

lib/error.g Outdated
PRINT_CURRENT_STATEMENT(context);
Print("\c");
PRINT_CURRENT_STATEMENT("*errout*", context);
PrintFto("*errout*", "\c");
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't -> Cannot

@ssiccha
Copy link
Contributor Author

ssiccha commented Jun 7, 2018

@fingolfin I will introduce a global variable that tells Where, WHERE, and ErrorInner where to send all error output.
The jupyter kernel can then set that variable instead of e.g. rebinding Error

@ssiccha ssiccha force-pushed the ss/make-print-curr-stat-redirectable branch from 8fab742 to fa4d1ce Compare June 7, 2018 15:37
src/error.c Outdated
Pr("Can not open output stream\n", 0L, 0L);
openedOutput = 0;
}

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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. :/

Copy link
Contributor Author

@ssiccha ssiccha Jun 7, 2018

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*";

Copy link
Member

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");
Copy link
Member

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.

Copy link
Contributor Author

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.

@ssiccha ssiccha force-pushed the ss/make-print-curr-stat-redirectable branch from fa4d1ce to 297ddfc Compare June 7, 2018 20:24
@codecov
Copy link

codecov bot commented Jun 7, 2018

Codecov Report

Merging #2529 into master will decrease coverage by <.01%.
The diff coverage is 29.62%.

@@            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
Impacted Files Coverage Δ
lib/error.g 36% <16.66%> (+0.2%) ⬆️
src/error.c 78.86% <55.55%> (-0.98%) ⬇️
src/hpc/threadapi.c 43.48% <0%> (-0.11%) ⬇️
src/stats.c 89.6% <0%> (+0.19%) ⬆️

@ssiccha ssiccha force-pushed the ss/make-print-curr-stat-redirectable branch 2 times, most recently from d1c6456 to e987cfb Compare June 7, 2018 21:30
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) {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ssiccha ssiccha force-pushed the ss/make-print-curr-stat-redirectable branch from e987cfb to e2700e9 Compare June 7, 2018 22:22
@ssiccha
Copy link
Contributor Author

ssiccha commented Jun 7, 2018

As long as #1815 is not merged, GAP_ERROR_STREAM can be used to feed weird streams to OpenOutputStream. E.g. if the variable is set to a closed stream GAP segfaults (maybe tries to write to it, or maybe OpenOutputStream itself crashes).

@olexandr-konovalov olexandr-konovalov added the gapdays2018-spring Issues and PRs that arose at http://www.gapdays.de/gap-jupyter-days2018 label Jun 8, 2018
@ssiccha ssiccha changed the title Make error output use *errout* consistently Make error output use the same stream consistently Jun 12, 2018
@ssiccha
Copy link
Contributor Author

ssiccha commented Jun 12, 2018

I just realized that one travis test-suite is failing..

@ssiccha ssiccha force-pushed the ss/make-print-curr-stat-redirectable branch from e2700e9 to 0ff91a5 Compare June 12, 2018 22:25
@ssiccha
Copy link
Contributor Author

ssiccha commented Jun 12, 2018

I fixed the bug. I forgot to do CloseOutputStream when returning early.

src/error.c Outdated
{
if (context == STATE(BottomLVars))
return 0;
Copy link
Member

@fingolfin fingolfin Jun 12, 2018

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?

Copy link
Contributor Author

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.

@ssiccha ssiccha force-pushed the ss/make-print-curr-stat-redirectable branch 2 times, most recently from 49ffb8c to 58f12d2 Compare June 12, 2018 22:47
@ssiccha
Copy link
Contributor Author

ssiccha commented Jun 12, 2018

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 */
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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".

@ssiccha ssiccha force-pushed the ss/make-print-curr-stat-redirectable branch 4 times, most recently from bb45e33 to 03583e3 Compare June 14, 2018 23:13
src/error.c Outdated
}
else {
fputs("gap: panic, can not open *errout*!\n", stderr);
SyExit(1);
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@ssiccha ssiccha force-pushed the ss/make-print-curr-stat-redirectable branch from 03583e3 to d071366 Compare June 16, 2018 09:53
- 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.
@ssiccha ssiccha force-pushed the ss/make-print-curr-stat-redirectable branch from d071366 to 4e59eff Compare June 18, 2018 09:05
@markuspf markuspf merged commit b19e0cc into gap-system:master Jun 18, 2018
@ssiccha ssiccha deleted the ss/make-print-curr-stat-redirectable branch June 28, 2018 22:40
@fingolfin fingolfin added the release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes label Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gapdays2018-spring Issues and PRs that arose at http://www.gapdays.de/gap-jupyter-days2018 release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes topic: kernel topic: library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants