-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from samstokes/policy-passdown
Pass client error policy down to snapshot and output plugin
- Loading branch information
Showing
16 changed files
with
333 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "error_policy.h" | ||
#include "protocol.h" | ||
|
||
#include <string.h> | ||
#include "postgres.h" | ||
|
||
error_policy_t parse_error_policy(const char *str) { | ||
if (strcmp(PROTOCOL_ERROR_POLICY_LOG, str) == 0) { | ||
return ERROR_POLICY_LOG; | ||
} else if (strcmp(PROTOCOL_ERROR_POLICY_EXIT, str) == 0) { | ||
return ERROR_POLICY_EXIT; | ||
} else { | ||
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), | ||
errmsg("invalid error_policy: %s", str))); | ||
return ERROR_POLICY_UNDEFINED; | ||
} | ||
} | ||
|
||
const char* error_policy_name(error_policy_t policy) { | ||
switch (policy) { | ||
case ERROR_POLICY_LOG: return PROTOCOL_ERROR_POLICY_LOG; | ||
case ERROR_POLICY_EXIT: return PROTOCOL_ERROR_POLICY_EXIT; | ||
case ERROR_POLICY_UNDEFINED: return "undefined (probably a bug)"; | ||
default: return "unknown (probably a bug)"; | ||
} | ||
} | ||
|
||
|
||
void error_policy_handle(error_policy_t policy, const char *message, const char *error) { | ||
switch (policy) { | ||
case ERROR_POLICY_LOG: | ||
elog(WARNING, "%s: %s", message, error); | ||
break; | ||
case ERROR_POLICY_EXIT: | ||
elog(ERROR, "%s: %s", message, error); | ||
default: | ||
elog(WARNING, "%s: %s", message, error); | ||
elog(ERROR, "error_policy_handle: unknown error policy!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef ERROR_POLICY_H | ||
#define ERROR_POLICY_H | ||
|
||
typedef enum { | ||
ERROR_POLICY_UNDEFINED = 0, | ||
ERROR_POLICY_LOG, | ||
ERROR_POLICY_EXIT | ||
} error_policy_t; | ||
|
||
static const error_policy_t DEFAULT_ERROR_POLICY = ERROR_POLICY_EXIT; | ||
|
||
error_policy_t parse_error_policy(const char *str); | ||
const char* error_policy_name(error_policy_t policy); | ||
|
||
/* Handles an error according to the supplied policy. | ||
* | ||
* `message` should describe the context in which the error occurred, e.g. what | ||
* the calling function was attempting to do. | ||
* | ||
* `error` should describe the error that occurred. | ||
* | ||
* This will call `ereport` with an appropriate severity depending on the | ||
* policy, so this may cause an early exit from the calling function. | ||
*/ | ||
void error_policy_handle(error_policy_t policy, const char *message, const char *error); | ||
|
||
#endif /* ERROR_POLICY_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.