* A data error happened. This code block will always be inside a PG_CATCH() * block right when a higher stack level produced an error. We handle the error * by checking which error mode is set (SREH or all-or-nothing) and do the right * thing accordingly. Note that we MUST have this code in a macro (as opposed * to a function) as elog_dismiss() has to be inlined with PG_CATCH in order to * ac
| 3142 | * changing me? take a look at FILEAM_HANDLE_ERROR in fileam.c as well. |
| 3143 | */ |
| 3144 | void |
| 3145 | HandleCopyError(CopyFromState cstate) |
| 3146 | { |
| 3147 | if (cstate->errMode == ALL_OR_NOTHING) |
| 3148 | { |
| 3149 | /* re-throw error and abort */ |
| 3150 | PG_RE_THROW(); |
| 3151 | } |
| 3152 | /* SREH must only handle data errors. all other errors must not be caught */ |
| 3153 | if (ERRCODE_TO_CATEGORY(elog_geterrcode()) != ERRCODE_DATA_EXCEPTION) |
| 3154 | { |
| 3155 | /* re-throw error and abort */ |
| 3156 | PG_RE_THROW(); |
| 3157 | } |
| 3158 | else |
| 3159 | { |
| 3160 | /* SREH - release error state and handle error */ |
| 3161 | MemoryContext oldcontext; |
| 3162 | ErrorData *edata; |
| 3163 | char *errormsg; |
| 3164 | CdbSreh *cdbsreh = cstate->cdbsreh; |
| 3165 | |
| 3166 | cdbsreh->processed++; |
| 3167 | |
| 3168 | oldcontext = MemoryContextSwitchTo(cstate->cdbsreh->badrowcontext); |
| 3169 | |
| 3170 | /* save a copy of the error info */ |
| 3171 | edata = CopyErrorData(); |
| 3172 | |
| 3173 | FlushErrorState(); |
| 3174 | |
| 3175 | /* |
| 3176 | * set the error message. Use original msg and add column name if available. |
| 3177 | * We do this even if we're not logging the errors, because |
| 3178 | * ErrorIfRejectLimit() below will use this information in the error message, |
| 3179 | * if the error count is reached. |
| 3180 | */ |
| 3181 | cdbsreh->rawdata->cursor = 0; |
| 3182 | cdbsreh->rawdata->data = cstate->line_buf.data; |
| 3183 | cdbsreh->rawdata->len = cstate->line_buf.len; |
| 3184 | |
| 3185 | cdbsreh->is_server_enc = true; |
| 3186 | cdbsreh->linenumber = cstate->cur_lineno; |
| 3187 | if (cstate->cur_attname) |
| 3188 | { |
| 3189 | errormsg = psprintf("%s, column %s", |
| 3190 | edata->message, cstate->cur_attname); |
| 3191 | } |
| 3192 | else |
| 3193 | { |
| 3194 | errormsg = edata->message; |
| 3195 | } |
| 3196 | cstate->cdbsreh->errmsg = errormsg; |
| 3197 | |
| 3198 | if (IS_LOG_TO_FILE(cstate->cdbsreh->logerrors)) |
| 3199 | { |
| 3200 | if (Gp_role == GP_ROLE_DISPATCH && !cstate->opts.on_segment) |
| 3201 | { |
no test coverage detected