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

When running non-interactively, errors should not HALT to the console but QUIT to the system #2215

Open
rebolbot opened this issue Apr 7, 2015 · 5 comments

Comments

@rebolbot
Copy link
Collaborator

rebolbot commented Apr 7, 2015

Submitted by: abolka

When you run rebol3 some-script.reb and %some-script.reb causes an uncaught Rebol error, the Rebol interpreter halts to the console, instead of quitting to the operating system. See the example code for an illustration of the problem.

The current "halt-on-error" behaviour is extremely annoying when executing Rebol scripts unsupervised (servers, batch processes, cron jobs, etc). It makes general "process has crashed" monitors useless, because from the outside a crashed script of course looks like it is still running. One workaround I have had to use for years is to use wrappers running echo quit/now | rebol3 some-script.reb.

Unfortunately, this issue also ties into personal preference and usage patterns. On Windows, when the Rebol interpreter is associated with .reb so that a script can be executed by simply double-clicking, halting to the console may well be what is expected -- as you may not see the error at all, otherwise.

Therefore, as a first fix I propose to introduce a new command-line option: --on-error [halt|quit]. Current behaviour would of course equal --on-error halt, whereas --on-error quit would return to the operating system when an error occurs. Further, --on-error quit must use an adequate process exit code to indicate that an error occurred -- on Linux, OS X, and Windows that'd mean returning a non-zero exit code.

With the command-line option in place, we can then discuss which behaviour should be the default. Ideally, we'd do a better job with choosing a good default depending on the actual environment (such as automatically choosing halt-on-error when a script is run because of double-clicking in Windows; if that is possible at all).

One final remark: when DO-ing a script from the Rebol console an error should of course continue to return back to the console, and not kill the console (irrespective of the --on-error option).

$ echo "REBOL [] 1 / 0" > div0.reb
$ rebol3 div0.reb
** Math error: attempt to divide by zero
** Where: / do either either either -apply-
** Near: / 0

>>  ;; Here's the problem, if you want a crash in the script to
    ;; also kill the script-running Rebol process.

CC - Data [ Version: r3 master Type: Bug Platform: All Category: Unspecified Reproduce: Always Fixed-in:none ]

@rebolbot
Copy link
Collaborator Author

rebolbot commented Apr 7, 2015

Submitted by: abolka

A related improvement is to print the error message (of the error which causes the process to quit) to the standard error stream -- that's already tracked by #1862.

@rebolbot
Copy link
Collaborator Author

Submitted by: abolka

Related discussion on GitHub's rebol/rebol issue tracker: rebol/rebol#246

@rebolbot
Copy link
Collaborator Author

Submitted by: abolka

As a first approximation towards a solution, I'd suggest an "on-error" command-line flag. "--on-error=halt" would reproduce the current behaviour, "--on-error=quit" would result in a sane behaviour typical command-line script execution and non-interactive execution. Further, I'd suggest exposing that option also via system/options, so that its default can be also set via %user.r. Finally, we should start thinking about switching the default from current "halt" to "quit".

Eventually, we could also introduce as a default a somewhat fancy trick as suggested by @hostilefork in the discussion on Github referenced above (let's call it "wait-on-error"): as a default, on error, wait for a few seconds to give an alert user a chance to halt into a debug session; if no user interaction occurs within those few seconds, quit.

@Oldes
Copy link

Oldes commented Aug 28, 2019

Not exactly what @earl initially requested, but I believe it is better, than what was original functionality:
Oldes/Rebol3@61c1383

Oldes referenced this issue in Oldes/Rebol3 Aug 28, 2019
Fixes issue #2215.

It is just a small modification, where in case of script error, the script QUITs instead of HALTing in REPL console. When `system/options/quiet = FALSE`, than there is 3s delay, before automatic quit. During this time user may use CTRL-C to HALT and enter the REPL for in place debugging.

When used `--halt` option, it enters the REPL as it was before without any wait. (Don't know if it is the best way, but I'm not sure if a new option is really needed for forcing REPL in case of errors).
@hostilefork
Copy link
Member

but I believe it is better, than what was original functionality

As mentioned I had this idea and implemented it, though people didn't particularly like it as a default. There was enough complaint that I made quitting the default, since it seemed to their feeling the solution was worse than the problem.

It might need more study to find out exactly what it was that people didn't like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants