Skip to content

Commit 3952e2f

Browse files
committed
revised exit code handling to make codes more informative (#24)
1 parent 9f145b3 commit 3952e2f

3 files changed

Lines changed: 27 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,22 @@
3535
cached.
3636

3737
At the end of document build, `codebraid` now exits with a non-zero exit
38-
code if there are errors in the document (#24). This is triggered by using
39-
invalid settings or by executing code that causes errors. It is also
40-
triggered by loading cached output from code that caused errors when it was
41-
originally executed (error state is cached). An exit code of 64 indicates
42-
an error serious enough to prevent or interrupt code execution. An exit
43-
code of 65 indicates an error that does not affect code execution, such as
44-
invalid settings related to displaying code output. An exit code of 1 still
45-
indicates that `codebraid` itself exited unexpectedly and failed to complete
46-
document build.
38+
code if there are errors or warnings (#24). This is triggered by using
39+
invalid settings or by executing code that causes errors or warnings. It is
40+
also triggered by loading cached output from code that caused errors or
41+
warnings when it was originally executed (error and warning state is
42+
cached). Exit codes are between 4 and 60 inclusive. The bits in the exit
43+
code are assigned value as follow:
44+
```
45+
0b00<doc_warn><exec_warn><doc_error><exec_error>00
46+
```
47+
Nonzero values for `<doc_warn>` and `<exec_warn>` indicate the presence of
48+
warnings from document build and from code execution, respectively.
49+
`<doc_error>` represents an error in document build that was not so severe
50+
that build was canceled with exit code 1, such as invalid settings related
51+
to displaying code output. `<exec_error>` represents an error from code
52+
execution. An exit code of 1 still indicates that `codebraid` itself exited
53+
unexpectedly or otherwise failed to complete document build.
4754

4855
* Reimplemented built-in code execution system and Jupyter kernel support as
4956
async. This makes possible new progress tracking and `live_output`

codebraid/codeprocessors/base.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,17 @@ def __init__(self,
8686

8787
@property
8888
def exit_code(self) -> int:
89+
code = 0b00000000
8990
if any(s.status.prevent_exec for s in self._sessions.values()):
90-
return 64
91-
if any(s.status.has_errors for s in self._sessions.values()):
92-
return 65
93-
if any(s.status.has_errors for s in self._sources.values()):
94-
return 65
95-
return 0
91+
code ^= 0b00000100
92+
if (any(s.status.has_errors and not s.status.prevent_exec for s in self._sessions.values()) or
93+
any(s.status.has_errors and not s.status.prevent_exec for s in self._sources.values())):
94+
code ^= 0b00001000
95+
if any(s.status.has_warnings for s in self._sessions.values()):
96+
code ^= 0b00010000
97+
# Once there are warnings related to document build, add condition:
98+
# code ^= 0b0010000
99+
return code
96100

97101

98102
def process(self):

codebraid/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# -*- coding: utf-8 -*-
22

33
from .fmtversion import get_version_plus_info
4-
__version__, __version_info__ = get_version_plus_info(0, 6, 0, 'dev', 5)
4+
__version__, __version_info__ = get_version_plus_info(0, 6, 0, 'dev', 6)

0 commit comments

Comments
 (0)