/* set attributes of the given exception to details from ErrorData */ void PLy_exception_set_with_details(PyObject *excclass, ErrorData *edata) { PyObject *args = NULL; PyObject *error = NULL; args = Py_BuildValue("(s)", edata->message); if (!args) goto failure; /* create a new exception with the error message as the parameter */ error = PyObject_CallObject(excclass, args); if (!error) goto failure; if (!set_string_attr(error, "sqlstate", unpack_sql_state(edata->sqlerrcode))) goto failure; if (!set_string_attr(error, "detail", edata->detail)) goto failure; if (!set_string_attr(error, "hint", edata->hint)) goto failure; if (!set_string_attr(error, "query", edata->internalquery)) goto failure; if (!set_string_attr(error, "schema_name", edata->schema_name)) goto failure; if (!set_string_attr(error, "table_name", edata->table_name)) goto failure; if (!set_string_attr(error, "column_name", edata->column_name)) goto failure; if (!set_string_attr(error, "datatype_name", edata->datatype_name)) goto failure; if (!set_string_attr(error, "constraint_name", edata->constraint_name)) goto failure; PyErr_SetObject(excclass, error); Py_DECREF(args); Py_DECREF(error); return; failure: Py_XDECREF(args); Py_XDECREF(error); elog(ERROR, "could not convert error to Python exception"); }
static void std_set_string_attr(attr_list l, char *name, char *value) { atom_t atom = attr_atom_from_string(name); if (atom == 0 ) return; set_string_attr(l, atom, value); }