Skip to content

Commit 148118c

Browse files
committed
Use exit codes to indicate different kinds of error
It's helpful if we can surface the error type to the user directly in Job Server, as we do for certain specific kinds of database error.
1 parent 444c17a commit 148118c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

ehrql/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ def main(args, environ=None):
124124
# Errors from definition files are already pre-formatted so we just write them
125125
# directly to stderr and exit
126126
print(str(exc), file=sys.stderr)
127-
sys.exit(1)
127+
sys.exit(10)
128128
except FileValidationError as exc:
129129
# Handle errors encountered while reading user-supplied data
130130
print(f"{exc.__class__.__name__}: {exc}", file=sys.stderr)
131-
sys.exit(1)
131+
sys.exit(11)
132132
except EHRQLPermissionError as exc:
133133
print(f"{exc.__class__.__name__}: {exc}", file=sys.stderr)
134-
sys.exit(1)
134+
sys.exit(12)
135135
except Exception as exc:
136136
# For functions which take a `backend_class` give that class the chance to set
137137
# the appropriate exit status for any errors

tests/functional/test_dump_dataset_sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def dataset_definition():
7878
with pytest.raises(SystemExit) as exc_info:
7979
call_cli("dump-dataset-sql", dataset_definition_path)
8080

81-
assert exc_info.value.code == 1
81+
assert exc_info.value.code > 0
8282
captured = call_cli.readouterr()
8383
assert "patients.date_of_birth.year + (patients.sex.is_null())" in captured.err
8484
assert "main.py" not in captured.err

0 commit comments

Comments
 (0)