Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found the original builder approach somewhat limiting and inefficient because we used to format strings before attempting to log (even if postgres did drop the log message).
Postgres elog API is somewhat complex, yet composable. When using C, APIs might also allow to report an optional soft error with
errsave
orereturn
. This cases didn't fit well with the existing Zig API.The new implementation follows the C macro API more closely by using the functional options pattern. The reporting functions like
ereport
,ereportNoJump
,errsave
, ... do capture the options likeerrcode
anderrmsg
in a struct. When reporting we callerrstart
which checks if the message is to be reported or not. Only iferrstart
returns true will we evaluate the options given byerrstart
orerrmsg
. This reduces CPU and memory usage especially for debugging logs.Finally
errfinish
will emit the log and eventually execute a long jump or return a Zig error.As the API now resembles the C-API more closely it is also easier to move the Postgres practices to Zig code more easiliy. The documentation in
elog.h
is (mostly?) true for the Zig implementation as well.Example usage of new API
Error with long jump:
Error report emitting a Zig error (we use
try
because some error levels will not return an error, but void).Soft error support (will do a longjump using ERROR level if escontext is no
ErrorSaveContext
node type):