2018-11-26 22:11:25 +01:00
|
|
|
#ifndef Py_CPYTHON_ERRORS_H
|
|
|
|
|
# error "this header file must not be included directly"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Error objects */
|
|
|
|
|
|
|
|
|
|
/* PyException_HEAD defines the initial segment of every exception class. */
|
|
|
|
|
#define PyException_HEAD PyObject_HEAD PyObject *dict;\
|
2022-04-16 19:59:52 +01:00
|
|
|
PyObject *args; PyObject *notes; PyObject *traceback;\
|
2018-11-26 22:11:25 +01:00
|
|
|
PyObject *context; PyObject *cause;\
|
|
|
|
|
char suppress_context;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
PyException_HEAD
|
|
|
|
|
} PyBaseExceptionObject;
|
|
|
|
|
|
2021-10-23 00:13:46 +01:00
|
|
|
typedef struct {
|
|
|
|
|
PyException_HEAD
|
|
|
|
|
PyObject *msg;
|
|
|
|
|
PyObject *excs;
|
|
|
|
|
} PyBaseExceptionGroupObject;
|
|
|
|
|
|
2018-11-26 22:11:25 +01:00
|
|
|
typedef struct {
|
|
|
|
|
PyException_HEAD
|
|
|
|
|
PyObject *msg;
|
|
|
|
|
PyObject *filename;
|
|
|
|
|
PyObject *lineno;
|
|
|
|
|
PyObject *offset;
|
bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)
To improve the user experience understanding what part of the error messages associated with SyntaxErrors is wrong, we can highlight the whole error range and not only place the caret at the first character. In this way:
>>> foo(x, z for z in range(10), t, w)
File "<stdin>", line 1
foo(x, z for z in range(10), t, w)
^
SyntaxError: Generator expression must be parenthesized
becomes
>>> foo(x, z for z in range(10), t, w)
File "<stdin>", line 1
foo(x, z for z in range(10), t, w)
^^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized
2021-04-23 14:27:05 +01:00
|
|
|
PyObject *end_lineno;
|
|
|
|
|
PyObject *end_offset;
|
2018-11-26 22:11:25 +01:00
|
|
|
PyObject *text;
|
|
|
|
|
PyObject *print_file_and_line;
|
|
|
|
|
} PySyntaxErrorObject;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
PyException_HEAD
|
|
|
|
|
PyObject *msg;
|
|
|
|
|
PyObject *name;
|
|
|
|
|
PyObject *path;
|
2022-10-25 23:56:59 +01:00
|
|
|
PyObject *name_from;
|
2018-11-26 22:11:25 +01:00
|
|
|
} PyImportErrorObject;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
PyException_HEAD
|
|
|
|
|
PyObject *encoding;
|
|
|
|
|
PyObject *object;
|
|
|
|
|
Py_ssize_t start;
|
|
|
|
|
Py_ssize_t end;
|
|
|
|
|
PyObject *reason;
|
|
|
|
|
} PyUnicodeErrorObject;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
PyException_HEAD
|
|
|
|
|
PyObject *code;
|
|
|
|
|
} PySystemExitObject;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
PyException_HEAD
|
|
|
|
|
PyObject *myerrno;
|
|
|
|
|
PyObject *strerror;
|
|
|
|
|
PyObject *filename;
|
|
|
|
|
PyObject *filename2;
|
|
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
|
PyObject *winerror;
|
|
|
|
|
#endif
|
|
|
|
|
Py_ssize_t written; /* only for BlockingIOError, -1 otherwise */
|
|
|
|
|
} PyOSErrorObject;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
PyException_HEAD
|
|
|
|
|
PyObject *value;
|
|
|
|
|
} PyStopIterationObject;
|
|
|
|
|
|
2021-04-14 15:10:33 +01:00
|
|
|
typedef struct {
|
|
|
|
|
PyException_HEAD
|
|
|
|
|
PyObject *name;
|
|
|
|
|
} PyNameErrorObject;
|
|
|
|
|
|
2021-04-14 02:36:07 +01:00
|
|
|
typedef struct {
|
|
|
|
|
PyException_HEAD
|
|
|
|
|
PyObject *obj;
|
|
|
|
|
PyObject *name;
|
|
|
|
|
} PyAttributeErrorObject;
|
|
|
|
|
|
2018-11-26 22:11:25 +01:00
|
|
|
/* Compatibility typedefs */
|
|
|
|
|
typedef PyOSErrorObject PyEnvironmentErrorObject;
|
|
|
|
|
#ifdef MS_WINDOWS
|
|
|
|
|
typedef PyOSErrorObject PyWindowsErrorObject;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Error handling definitions */
|
|
|
|
|
|
|
|
|
|
PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *);
|
2020-05-07 15:42:33 +02:00
|
|
|
PyAPI_FUNC(_PyErr_StackItem*) _PyErr_GetTopmostException(PyThreadState *tstate);
|
2022-04-15 19:57:47 +01:00
|
|
|
PyAPI_FUNC(PyObject*) _PyErr_GetHandledException(PyThreadState *);
|
|
|
|
|
PyAPI_FUNC(void) _PyErr_SetHandledException(PyThreadState *, PyObject *);
|
2020-01-13 17:30:14 +01:00
|
|
|
PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **);
|
2018-11-26 22:11:25 +01:00
|
|
|
|
|
|
|
|
/* Context manipulation (PEP 3134) */
|
|
|
|
|
|
2023-04-01 21:30:23 +01:00
|
|
|
Py_DEPRECATED(3.12) PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
|
2023-02-08 09:31:12 +00:00
|
|
|
PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);
|
2018-11-26 22:11:25 +01:00
|
|
|
|
|
|
|
|
/* Like PyErr_Format(), but saves current exception as __context__ and
|
|
|
|
|
__cause__.
|
|
|
|
|
*/
|
|
|
|
|
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
|
|
|
|
|
PyObject *exception,
|
|
|
|
|
const char *format, /* ASCII-encoded string */
|
|
|
|
|
...
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/* In exceptions.c */
|
|
|
|
|
|
2023-03-16 10:16:01 +00:00
|
|
|
PyAPI_FUNC(int) _PyException_AddNote(
|
|
|
|
|
PyObject *exc,
|
|
|
|
|
PyObject *note);
|
|
|
|
|
|
2023-05-30 16:50:23 +01:00
|
|
|
PyAPI_FUNC(PyObject*) PyUnstable_Exc_PrepReraiseStar(
|
|
|
|
|
PyObject *orig,
|
|
|
|
|
PyObject *excs);
|
|
|
|
|
|
2018-11-26 22:11:25 +01:00
|
|
|
/* In signalmodule.c */
|
|
|
|
|
|
|
|
|
|
int PySignal_SetWakeupFd(int fd);
|
2019-02-23 15:40:43 -07:00
|
|
|
PyAPI_FUNC(int) _PyErr_CheckSignals(void);
|
2018-11-26 22:11:25 +01:00
|
|
|
|
|
|
|
|
/* Support for adding program text to SyntaxErrors */
|
|
|
|
|
|
|
|
|
|
PyAPI_FUNC(void) PyErr_SyntaxLocationObject(
|
|
|
|
|
PyObject *filename,
|
|
|
|
|
int lineno,
|
|
|
|
|
int col_offset);
|
|
|
|
|
|
bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)
To improve the user experience understanding what part of the error messages associated with SyntaxErrors is wrong, we can highlight the whole error range and not only place the caret at the first character. In this way:
>>> foo(x, z for z in range(10), t, w)
File "<stdin>", line 1
foo(x, z for z in range(10), t, w)
^
SyntaxError: Generator expression must be parenthesized
becomes
>>> foo(x, z for z in range(10), t, w)
File "<stdin>", line 1
foo(x, z for z in range(10), t, w)
^^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized
2021-04-23 14:27:05 +01:00
|
|
|
PyAPI_FUNC(void) PyErr_RangedSyntaxLocationObject(
|
|
|
|
|
PyObject *filename,
|
|
|
|
|
int lineno,
|
|
|
|
|
int col_offset,
|
|
|
|
|
int end_lineno,
|
|
|
|
|
int end_col_offset);
|
|
|
|
|
|
2018-11-26 22:11:25 +01:00
|
|
|
PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
|
|
|
|
|
PyObject *filename,
|
|
|
|
|
int lineno);
|
|
|
|
|
|
2021-11-20 14:36:07 +00:00
|
|
|
PyAPI_FUNC(PyObject *) _PyErr_ProgramDecodedTextObject(
|
|
|
|
|
PyObject *filename,
|
|
|
|
|
int lineno,
|
|
|
|
|
const char* encoding);
|
|
|
|
|
|
2018-11-26 22:11:25 +01:00
|
|
|
PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
|
|
|
|
|
PyObject *object,
|
|
|
|
|
Py_ssize_t start,
|
|
|
|
|
Py_ssize_t end,
|
|
|
|
|
const char *reason /* UTF-8 encoded string */
|
|
|
|
|
);
|
|
|
|
|
|
2019-05-27 08:57:14 +02:00
|
|
|
PyAPI_FUNC(void) _PyErr_WriteUnraisableMsg(
|
|
|
|
|
const char *err_msg,
|
|
|
|
|
PyObject *obj);
|
2018-11-26 22:11:25 +01:00
|
|
|
|
2020-03-07 00:54:20 +01:00
|
|
|
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFunc(
|
|
|
|
|
const char *func,
|
|
|
|
|
const char *message);
|
|
|
|
|
|
2020-03-25 19:27:36 +01:00
|
|
|
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat(
|
|
|
|
|
const char *func,
|
|
|
|
|
const char *format,
|
|
|
|
|
...);
|
|
|
|
|
|
2022-10-25 23:56:59 +01:00
|
|
|
extern PyObject *_PyErr_SetImportErrorWithNameFrom(
|
|
|
|
|
PyObject *,
|
|
|
|
|
PyObject *,
|
|
|
|
|
PyObject *,
|
|
|
|
|
PyObject *);
|
|
|
|
|
|
|
|
|
|
|
2022-06-20 16:04:52 +02:00
|
|
|
#define Py_FatalError(message) _Py_FatalErrorFunc(__func__, (message))
|