REBOL3 tracker
  0.9.12 beta
Ticket #0001734 User: anonymous

Project:



rss
TypeBug Statusproblem Date31-Oct-2010 15:23
Versionalpha 109 CategoryUnspecified Submitted byabolka
PlatformAll Severityminor Prioritynormal

Summary Exit code of QUIT/return is not returned for scripts
Description When using QUIT/return directly from the console, all is fine. The interpreter quits and the exit code is what was passed to QUIT/return. For example:

$ rebol3 -q
>> quit/return 42
$ echo $?
42

However, when using QUIT/return in a script, the return code is swallowed (see the example code).

A temporary workaround is to use QUIT/now/return instead of QUIT/return.
Example code
$ cat quit-return.r 
REBOL []
quit/return 42

$ rebol3 -qs quit-return.r

$ echo $?
0
# expected: 42

Assigned ton/a Fixed inalpha 110 Last Update2-Nov-2010 19:41


Comments
(0002713)
BrianH
31-Oct-2010 23:47

It's not the exit code that is swallowed, it is the entire QUIT/return that is swallowed in scripts. Scripts are run with CATCH/quit, specifically to catch QUIT calls in scripts. The QUIT/return in your script is being caught, and then since the script was called from the command line the entire interpreter quits on its own after the script finishes.

This is all by design. QUIT/now is the workaround for this, but it's not temporary, it's the permanent solution. This is done so that a QUIT wrapper without the /now option can be provided to scripts that you don't want to allow to do a full quit. This is not a bug.
(0002724)
abolka
1-Nov-2010 04:54

"The QUIT/return in your script is being caught, and then since the script was called from the command line the entire interpreter quits on its own after the script finishes."

Why does the interpreter not pass along the exit code? That is the bug I am reporting. Please reopen.
(0002725)
Carl
1-Nov-2010 05:40

A couple years back, we modified QUIT significantly to provide a more desirable behavior for nested scripts. The /now refinement was added to *force* a quit immediately rather than unwinding. I don't remember all the details, but we have a history written down somewhere (and it needs to be put into the QUIT doc.)

In theory, when the outer layer unwinds, if that layer provided a /return value, the process exit should return it. I would consider it a bug if it does not. So, I've changed the status of this bug to 'waiting.

What Brian is saying above is that you cannot always count on that behavior, because QUIT without /now is a processed quit, and other actions may occur on the way out.
(0002740)
BrianH
1-Nov-2010 21:59

I apologize for not realizing something obvious in retrospect: If you call a script from the command line then *it* is the top-level script, and so is the script that we want to protect from being quitted by the scripts that it calls. There is no reason to run the top-level script itself with CATCH/quit - DO will do (the native version, after the script has been loaded, since DO of a file *does* need to use CATCH/quit internally).

I'm sorry, I was probably the one that introduced this bug when I moved CATCH/quit outside of MAKE module!.
(0002755)
BrianH
2-Nov-2010 08:36

Alpha 110 status: I checked the source in the git repository and this bug is not fixed there, nor is it fixed in the source of sys/start when I run at --boot sys and look at it. I can't test this because QUIT/return doesn't work at all on Windows, apparently. Changing this ticket to tested is going to have to wait for someone else to test it, but based on the source I am guessing it is not yet fixed.
(0002761)
abolka
2-Nov-2010 19:28

Seems the `return catch/quit [..]` in the sys/start source does the trick.

Works with both A110 Linux and an A110 Win32 "Console-mode" binary built from the A110 hostkit.
(0002762)
BrianH
2-Nov-2010 19:41

OK, since the return catch/quit [..] part is only in the script section, not for modules, and doesn't work with the --halt option, this ticket must be marked as a problem. The real fix can go in the next version.

Date User Field Action Change
4-Nov-2010 22:30 abolka Comment : 0002761 Modified -
2-Nov-2010 19:41 BrianH Status Modified tested => problem
2-Nov-2010 19:41 BrianH Comment : 0002762 Added -
2-Nov-2010 19:28 abolka Status Modified built => tested
2-Nov-2010 19:28 abolka Comment : 0002761 Added -
2-Nov-2010 08:36 BrianH Comment : 0002755 Added -
1-Nov-2010 22:00 BrianH Comment : 0002740 Modified -
1-Nov-2010 21:59 BrianH Comment : 0002740 Added -
1-Nov-2010 05:56 carl Status Modified waiting => built
1-Nov-2010 05:56 carl Fixedin Modified => alpha 110
1-Nov-2010 05:54 abolka Severity Modified not a bug => minor
1-Nov-2010 05:42 carl Comment : 0002725 Modified -
1-Nov-2010 05:40 carl Status Modified dismissed => waiting
1-Nov-2010 05:40 carl Comment : 0002725 Added -
1-Nov-2010 04:55 abolka Comment : 0002724 Modified -
1-Nov-2010 04:54 abolka Comment : 0002724 Added -
31-Oct-2010 23:49 BrianH Comment : 0002713 Modified -
31-Oct-2010 23:48 BrianH Status Modified submitted => dismissed
31-Oct-2010 23:48 BrianH Severity Modified minor => not a bug
31-Oct-2010 23:47 BrianH Comment : 0002713 Added -
31-Oct-2010 16:08 abolka Code Modified -
31-Oct-2010 16:08 abolka Description Modified -
31-Oct-2010 15:23 abolka Ticket Added -