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

interp: implement ERR and EXIT trap #650

Closed
wants to merge 2 commits into from

Conversation

zimbatm
Copy link
Contributor

@zimbatm zimbatm commented Dec 27, 2020

This is still a WIP. The ERR and EXIT callbacks are not really at the right
place I think, they seem to fire on every shell prompt in gosh.

@mvdan
Copy link
Owner

mvdan commented Dec 27, 2020

I'll still be quite AFK tomorrow, but after that I'll start being around again. Let me know if you want some help and I'm happy to do that - possibly over Slack, since it's more instantaneous :)

@zimbatm
Copy link
Contributor Author

zimbatm commented Dec 28, 2020

Ok, I think this is not over yet. I'm also in holiday mode but I might jump into Slack at some point.

@mvdan
Copy link
Owner

mvdan commented Jan 29, 2021

@zimbatm do you want to continue with this? I'm aiming for a v3.3.0 release by the end of February, and I think including the features/fixes needed by direnv would be nice :) I'm happy to take over this PR if you don't have spare cycles at the moment, but I thought I'd ask before I do.

@zimbatm
Copy link
Contributor Author

zimbatm commented Jan 31, 2021

Go for it. I did the mini spike and now it has swapped out of priority.

Thanks a lot for all the wonderful work you're doing.

mvdan added a commit that referenced this pull request Feb 16, 2021
Thanks to Jonas Chevalier for implementing the bulk of this on
#650.

His changes were mainly implementing the "trap" builtin itself,
recording the trap callbacks in new fields, and refactoring the exit
logic to allow calling those callbacks. And, of course, the tests.

My changes on top extend the tests a bit, make Runner.stmtSync call
the ERR trap callback when a simple command fails, and make Runner.Run
call the EXIT trap callback when done interpreting an entire *File.

That last change is backwards compatible, since the only noticeable
effect should be that Run on a *File can call EXIT trap callbacks. Those
were not supported before, so no existing program should break.

Finally, note that we add a test case that would make the Runner get
stuck in a callback loop without the handlingTrap boolean field.
@mvdan
Copy link
Owner

mvdan commented Feb 16, 2021

I've finished up your patch in a new PR: #666

A review or a confirmation that it works for you would be welcome. If you need anything else implemented, an option is also to review and merge that PR and send follow-up ones :)

mvdan added a commit that referenced this pull request Feb 16, 2021
Thanks to Jonas Chevalier for implementing the bulk of this on
#650.

His changes were mainly implementing the "trap" builtin itself,
recording the trap callbacks in new fields, and refactoring the exit
logic to allow calling those callbacks. And, of course, the tests.

My changes on top extend the tests a bit, make Runner.stmtSync call
the ERR trap callback when a simple command fails, and make Runner.Run
call the EXIT trap callback when done interpreting an entire *File.

That last change is backwards compatible, since the only noticeable
effect should be that Run on a *File can call EXIT trap callbacks. Those
were not supported before, so no existing program should break.

Finally, note that we add a test case that would make the Runner get
stuck in a callback loop without the handlingTrap boolean field.

Fixes #635.
@mvdan
Copy link
Owner

mvdan commented Feb 24, 2021

I'm merging that PR for now, and I'll close this one too - any testing or thoughts still welcome, of course. I just want to start preparing for an upcoming release :)

mvdan added a commit that referenced this pull request Feb 24, 2021
Thanks to Jonas Chevalier for implementing the bulk of this on
#650.

His changes were mainly implementing the "trap" builtin itself,
recording the trap callbacks in new fields, and refactoring the exit
logic to allow calling those callbacks. And, of course, the tests.

My changes on top extend the tests a bit, make Runner.stmtSync call
the ERR trap callback when a simple command fails, and make Runner.Run
call the EXIT trap callback when done interpreting an entire *File.

That last change is backwards compatible, since the only noticeable
effect should be that Run on a *File can call EXIT trap callbacks. Those
were not supported before, so no existing program should break.

Finally, note that we add a test case that would make the Runner get
stuck in a callback loop without the handlingTrap boolean field.

Fixes #635.
mvdan added a commit that referenced this pull request Feb 24, 2021
Thanks to Jonas Chevalier for implementing the bulk of this on
#650.

His changes were mainly implementing the "trap" builtin itself,
recording the trap callbacks in new fields, and refactoring the exit
logic to allow calling those callbacks. And, of course, the tests.

My changes on top extend the tests a bit, make Runner.stmtSync call
the ERR trap callback when a simple command fails, and make Runner.Run
call the EXIT trap callback when done interpreting an entire *File.

That last change is backwards compatible, since the only noticeable
effect should be that Run on a *File can call EXIT trap callbacks. Those
were not supported before, so no existing program should break.

Finally, note that we add a test case that would make the Runner get
stuck in a callback loop without the handlingTrap boolean field.

Fixes #635.
@mvdan
Copy link
Owner

mvdan commented Feb 24, 2021

Merged; closing.

@mvdan mvdan closed this Feb 24, 2021
@zimbatm zimbatm deleted the trap-err-exit branch February 26, 2021 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants