Coverage for cc_modules/cc_exception.py: 80%
10 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-15 14:23 +0100
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-15 14:23 +0100
1"""
2camcops_server/cc_modules/cc_exception.py
4===============================================================================
6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CamCOPS.
11 CamCOPS is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 CamCOPS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
24===============================================================================
26**Exception-handling functions.**
28"""
30import logging
31from typing import NoReturn
33from cardinal_pythonlib.logs import BraceStyleAdapter
35log = BraceStyleAdapter(logging.getLogger(__name__))
38# =============================================================================
39# Exception constants
40# =============================================================================
42STR_FORMAT_EXCEPTIONS = (
43 # Exceptions that can be raised by str.format()
44 IndexError, # missing positional parameter: "{}, {}".format(1)
45 KeyError, # missing named parameter: "{x}".format(y=2)
46 ValueError, # e.g. unmatched brace: "{x".format(x=1)
47)
50# =============================================================================
51# Exceptions
52# =============================================================================
55class FhirExportException(Exception):
56 pass
59# =============================================================================
60# Exception functions
61# =============================================================================
64def raise_runtime_error(msg: str) -> NoReturn:
65 """
66 Reports an error message to the Python log and raises a
67 :exc:`RuntimeError`.
68 """
69 log.critical(msg)
70 raise RuntimeError(msg)