PostgreSQL Source Code  git master
miscnodes.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * miscnodes.h
4  * Definitions for hard-to-classify node types.
5  *
6  * Node types declared here are not part of parse trees, plan trees,
7  * or execution state trees. We only assign them NodeTag values because
8  * IsA() tests provide a convenient way to disambiguate what kind of
9  * structure is being passed through assorted APIs, such as function
10  * "context" pointers.
11  *
12  *
13  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
14  * Portions Copyright (c) 1994, Regents of the University of California
15  *
16  * src/include/nodes/miscnodes.h
17  *
18  *-------------------------------------------------------------------------
19  */
20 #ifndef MISCNODES_H
21 #define MISCNODES_H
22 
23 #include "nodes/nodes.h"
24 
25 /*
26  * ErrorSaveContext -
27  * function call context node for handling of "soft" errors
28  *
29  * A caller wishing to trap soft errors must initialize a struct like this
30  * with all fields zero/NULL except for the NodeTag. Optionally, set
31  * details_wanted = true if more than the bare knowledge that a soft error
32  * occurred is required. The struct is then passed to a SQL-callable function
33  * via the FunctionCallInfo.context field; or below the level of SQL calls,
34  * it could be passed to a subroutine directly.
35  *
36  * After calling code that might report an error this way, check
37  * error_occurred to see if an error happened. If so, and if details_wanted
38  * is true, error_data has been filled with error details (stored in the
39  * callee's memory context!). FreeErrorData() can be called to release
40  * error_data, although that step is typically not necessary if the called
41  * code was run in a short-lived context.
42  */
43 typedef struct ErrorSaveContext
44 {
46  bool error_occurred; /* set to true if we detect a soft error */
47  bool details_wanted; /* does caller want more info than that? */
48  ErrorData *error_data; /* details of error, if so */
50 
51 /* Often-useful macro for checking if a soft error was reported */
52 #define SOFT_ERROR_OCCURRED(escontext) \
53  ((escontext) != NULL && IsA(escontext, ErrorSaveContext) && \
54  ((ErrorSaveContext *) (escontext))->error_occurred)
55 
56 #endif /* MISCNODES_H */
struct ErrorSaveContext ErrorSaveContext
NodeTag
Definition: nodes.h:27
bool details_wanted
Definition: miscnodes.h:47
ErrorData * error_data
Definition: miscnodes.h:48
bool error_occurred
Definition: miscnodes.h:46
NodeTag type
Definition: miscnodes.h:45