codekingpro/portable-devtools
115k
1/*-------------------------------------------------------------------------2 *3 * miscnodes.h4 * 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 because8 * IsA() tests provide a convenient way to disambiguate what kind of9 * structure is being passed through assorted APIs, such as function10 * "context" pointers.11 *12 *13 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group14 * Portions Copyright (c) 1994, Regents of the University of California15 *16 * src/include/nodes/miscnodes.h17 *18 *-------------------------------------------------------------------------19 */20#ifndef MISCNODES_H21#define MISCNODES_H22 23#include "nodes/nodes.h"24 25/*26 * ErrorSaveContext -27 * function call context node for handling of "soft" errors28 *29 * A caller wishing to trap soft errors must initialize a struct like this30 * with all fields zero/NULL except for the NodeTag. Optionally, set31 * details_wanted = true if more than the bare knowledge that a soft error32 * occurred is required. The struct is then passed to a SQL-callable function33 * 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, check37 * error_occurred to see if an error happened. If so, and if details_wanted38 * is true, error_data has been filled with error details (stored in the39 * callee's memory context!). FreeErrorData() can be called to release40 * error_data, although that step is typically not necessary if the called41 * code was run in a short-lived context.42 */43typedef struct ErrorSaveContext44{45 NodeTag type;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 */49} ErrorSaveContext;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 */57 