@@ -183,7 +183,14 @@ struct json_ctx
183183#define oauth_json_has_error (ctx ) \
184184 (PQExpBufferDataBroken((ctx)->errbuf) || (ctx)->errmsg)
185185
186- #define oauth_json_set_error (ctx , ...) \
186+ #define oauth_json_set_error (ctx , fmt , ...) \
187+ do { \
188+ appendPQExpBuffer(&(ctx)->errbuf, libpq_gettext(fmt), ##__VA_ARGS__); \
189+ (ctx)->errmsg = (ctx)->errbuf.data; \
190+ } while (0)
191+
192+ /* An untranslated version of oauth_json_set_error(). */
193+ #define oauth_json_set_error_internal (ctx , ...) \
187194 do { \
188195 appendPQExpBuffer(&(ctx)->errbuf, __VA_ARGS__); \
189196 (ctx)->errmsg = (ctx)->errbuf.data; \
@@ -199,13 +206,13 @@ oauth_json_object_start(void *state)
199206 Assert (ctx -> nested == 1 );
200207
201208 oauth_json_set_error (ctx ,
202- libpq_gettext ( "field \"%s\" must be a string" ) ,
209+ "field \"%s\" must be a string" ,
203210 ctx -> target_field_name );
204211 }
205212
206213 ++ ctx -> nested ;
207214 if (ctx -> nested > MAX_SASL_NESTING_LEVEL )
208- oauth_json_set_error (ctx , libpq_gettext ( "JSON is too deeply nested" ) );
215+ oauth_json_set_error (ctx , "JSON is too deeply nested" );
209216
210217 return oauth_json_has_error (ctx ) ? JSON_SEM_ACTION_FAILED : JSON_SUCCESS ;
211218}
@@ -254,20 +261,20 @@ oauth_json_array_start(void *state)
254261
255262 if (!ctx -> nested )
256263 {
257- ctx -> errmsg = libpq_gettext ( "top-level element must be an object" );
264+ oauth_json_set_error ( ctx , "top-level element must be an object" );
258265 }
259266 else if (ctx -> target_field )
260267 {
261268 Assert (ctx -> nested == 1 );
262269
263270 oauth_json_set_error (ctx ,
264- libpq_gettext ( "field \"%s\" must be a string" ) ,
271+ "field \"%s\" must be a string" ,
265272 ctx -> target_field_name );
266273 }
267274
268275 ++ ctx -> nested ;
269276 if (ctx -> nested > MAX_SASL_NESTING_LEVEL )
270- oauth_json_set_error (ctx , libpq_gettext ( "JSON is too deeply nested" ) );
277+ oauth_json_set_error (ctx , "JSON is too deeply nested" );
271278
272279 return oauth_json_has_error (ctx ) ? JSON_SEM_ACTION_FAILED : JSON_SUCCESS ;
273280}
@@ -288,7 +295,7 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
288295
289296 if (!ctx -> nested )
290297 {
291- ctx -> errmsg = libpq_gettext ( "top-level element must be an object" );
298+ oauth_json_set_error ( ctx , "top-level element must be an object" );
292299 return JSON_SEM_ACTION_FAILED ;
293300 }
294301
@@ -301,9 +308,9 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
301308 * Assert and don't continue any further for production builds.
302309 */
303310 Assert (false);
304- oauth_json_set_error (ctx ,
305- "internal error: target scalar found at nesting level %d during OAUTHBEARER parsing" ,
306- ctx -> nested );
311+ oauth_json_set_error_internal (ctx ,
312+ "internal error: target scalar found at nesting level %d during OAUTHBEARER parsing" ,
313+ ctx -> nested );
307314 return JSON_SEM_ACTION_FAILED ;
308315 }
309316
@@ -314,7 +321,7 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
314321 if (* ctx -> target_field )
315322 {
316323 oauth_json_set_error (ctx ,
317- libpq_gettext ( "field \"%s\" is duplicated" ) ,
324+ "field \"%s\" is duplicated" ,
318325 ctx -> target_field_name );
319326 return JSON_SEM_ACTION_FAILED ;
320327 }
@@ -323,7 +330,7 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
323330 if (type != JSON_TOKEN_STRING )
324331 {
325332 oauth_json_set_error (ctx ,
326- libpq_gettext ( "field \"%s\" must be a string" ) ,
333+ "field \"%s\" must be a string" ,
327334 ctx -> target_field_name );
328335 return JSON_SEM_ACTION_FAILED ;
329336 }
0 commit comments