🌐 AI搜索 & 代理 主页
Skip to content

Commit 301a1dc

Browse files
committed
libpq-oauth: Don't translate internal errors
Some error messages are generated when OAuth multiplexer operations fail unexpectedly in the client. Álvaro pointed out that these are both difficult to translate idiomatically (as they use internal terminology heavily) and of dubious translation value to end users (since they're going to need to get developer help anyway). The response parsing engine has a similar issue. Remove these from the translation files by introducing internal variants of actx_error() and oauth_parse_set_error(). Suggested-by: Álvaro Herrera <alvherre@kurilemu.de> Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Discussion: https://postgr.es/m/CAOYmi%2BkQQ8vpRcoSrA5EQ98Wa3G6jFj1yRHs6mh1V7ohkTC7JA%40mail.gmail.com Backpatch-through: 18
1 parent ea3370b commit 301a1dc

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

src/interfaces/libpq-oauth/oauth-curl.c

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,16 @@ pg_fe_cleanup_oauth_flow(PGconn *conn)
368368

369369
/*
370370
* Macros for manipulating actx->errbuf. actx_error() translates and formats a
371-
* string for you; actx_error_str() appends a string directly without
372-
* translation.
371+
* string for you, actx_error_internal() is the untranslated equivalent, and
372+
* actx_error_str() appends a string directly (also without translation).
373373
*/
374374

375375
#define actx_error(ACTX, FMT, ...) \
376376
appendPQExpBuffer(&(ACTX)->errbuf, libpq_gettext(FMT), ##__VA_ARGS__)
377377

378+
#define actx_error_internal(ACTX, FMT, ...) \
379+
appendPQExpBuffer(&(ACTX)->errbuf, FMT, ##__VA_ARGS__)
380+
378381
#define actx_error_str(ACTX, S) \
379382
appendPQExpBufferStr(&(ACTX)->errbuf, S)
380383

@@ -462,6 +465,9 @@ struct oauth_parse
462465
#define oauth_parse_set_error(ctx, fmt, ...) \
463466
appendPQExpBuffer((ctx)->errbuf, libpq_gettext(fmt), ##__VA_ARGS__)
464467

468+
#define oauth_parse_set_error_internal(ctx, fmt, ...) \
469+
appendPQExpBuffer((ctx)->errbuf, fmt, ##__VA_ARGS__)
470+
465471
static void
466472
report_type_mismatch(struct oauth_parse *ctx)
467473
{
@@ -537,9 +543,9 @@ oauth_json_object_field_start(void *state, char *name, bool isnull)
537543
if (ctx->active)
538544
{
539545
Assert(false);
540-
oauth_parse_set_error(ctx,
541-
"internal error: started field '%s' before field '%s' was finished",
542-
name, ctx->active->name);
546+
oauth_parse_set_error_internal(ctx,
547+
"internal error: started field \"%s\" before field \"%s\" was finished",
548+
name, ctx->active->name);
543549
return JSON_SEM_ACTION_FAILED;
544550
}
545551

@@ -589,9 +595,9 @@ oauth_json_object_end(void *state)
589595
if (!ctx->nested && ctx->active)
590596
{
591597
Assert(false);
592-
oauth_parse_set_error(ctx,
593-
"internal error: field '%s' still active at end of object",
594-
ctx->active->name);
598+
oauth_parse_set_error_internal(ctx,
599+
"internal error: field \"%s\" still active at end of object",
600+
ctx->active->name);
595601
return JSON_SEM_ACTION_FAILED;
596602
}
597603

@@ -645,9 +651,9 @@ oauth_json_array_end(void *state)
645651
if (ctx->nested != 2 || ctx->active->type != JSON_TOKEN_ARRAY_START)
646652
{
647653
Assert(false);
648-
oauth_parse_set_error(ctx,
649-
"internal error: found unexpected array end while parsing field '%s'",
650-
ctx->active->name);
654+
oauth_parse_set_error_internal(ctx,
655+
"internal error: found unexpected array end while parsing field \"%s\"",
656+
ctx->active->name);
651657
return JSON_SEM_ACTION_FAILED;
652658
}
653659

@@ -700,19 +706,19 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
700706
if (ctx->nested != 1)
701707
{
702708
Assert(false);
703-
oauth_parse_set_error(ctx,
704-
"internal error: scalar target found at nesting level %d",
705-
ctx->nested);
709+
oauth_parse_set_error_internal(ctx,
710+
"internal error: scalar target found at nesting level %d",
711+
ctx->nested);
706712
return JSON_SEM_ACTION_FAILED;
707713
}
708714

709715
/* ...and that a result has not already been set. */
710716
if (*field->scalar)
711717
{
712718
Assert(false);
713-
oauth_parse_set_error(ctx,
714-
"internal error: scalar field '%s' would be assigned twice",
715-
ctx->active->name);
719+
oauth_parse_set_error_internal(ctx,
720+
"internal error: scalar field \"%s\" would be assigned twice",
721+
ctx->active->name);
716722
return JSON_SEM_ACTION_FAILED;
717723
}
718724

@@ -732,9 +738,9 @@ oauth_json_scalar(void *state, char *token, JsonTokenType type)
732738
if (ctx->nested != 2)
733739
{
734740
Assert(false);
735-
oauth_parse_set_error(ctx,
736-
"internal error: array member found at nesting level %d",
737-
ctx->nested);
741+
oauth_parse_set_error_internal(ctx,
742+
"internal error: array member found at nesting level %d",
743+
ctx->nested);
738744
return JSON_SEM_ACTION_FAILED;
739745
}
740746

@@ -1180,20 +1186,20 @@ setup_multiplexer(struct async_ctx *actx)
11801186
actx->mux = epoll_create1(EPOLL_CLOEXEC);
11811187
if (actx->mux < 0)
11821188
{
1183-
actx_error(actx, "failed to create epoll set: %m");
1189+
actx_error_internal(actx, "failed to create epoll set: %m");
11841190
return false;
11851191
}
11861192

11871193
actx->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
11881194
if (actx->timerfd < 0)
11891195
{
1190-
actx_error(actx, "failed to create timerfd: %m");
1196+
actx_error_internal(actx, "failed to create timerfd: %m");
11911197
return false;
11921198
}
11931199

11941200
if (epoll_ctl(actx->mux, EPOLL_CTL_ADD, actx->timerfd, &ev) < 0)
11951201
{
1196-
actx_error(actx, "failed to add timerfd to epoll set: %m");
1202+
actx_error_internal(actx, "failed to add timerfd to epoll set: %m");
11971203
return false;
11981204
}
11991205

@@ -1202,8 +1208,7 @@ setup_multiplexer(struct async_ctx *actx)
12021208
actx->mux = kqueue();
12031209
if (actx->mux < 0)
12041210
{
1205-
/*- translator: the term "kqueue" (kernel queue) should not be translated */
1206-
actx_error(actx, "failed to create kqueue: %m");
1211+
actx_error_internal(actx, "failed to create kqueue: %m");
12071212
return false;
12081213
}
12091214

@@ -1216,7 +1221,7 @@ setup_multiplexer(struct async_ctx *actx)
12161221
actx->timerfd = kqueue();
12171222
if (actx->timerfd < 0)
12181223
{
1219-
actx_error(actx, "failed to create timer kqueue: %m");
1224+
actx_error_internal(actx, "failed to create timer kqueue: %m");
12201225
return false;
12211226
}
12221227

@@ -1260,7 +1265,7 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
12601265
break;
12611266

12621267
default:
1263-
actx_error(actx, "unknown libcurl socket operation: %d", what);
1268+
actx_error_internal(actx, "unknown libcurl socket operation: %d", what);
12641269
return -1;
12651270
}
12661271

@@ -1277,15 +1282,15 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
12771282
switch (op)
12781283
{
12791284
case EPOLL_CTL_ADD:
1280-
actx_error(actx, "could not add to epoll set: %m");
1285+
actx_error_internal(actx, "could not add to epoll set: %m");
12811286
break;
12821287

12831288
case EPOLL_CTL_DEL:
1284-
actx_error(actx, "could not delete from epoll set: %m");
1289+
actx_error_internal(actx, "could not delete from epoll set: %m");
12851290
break;
12861291

12871292
default:
1288-
actx_error(actx, "could not update epoll set: %m");
1293+
actx_error_internal(actx, "could not update epoll set: %m");
12891294
}
12901295

12911296
return -1;
@@ -1335,7 +1340,7 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
13351340
break;
13361341

13371342
default:
1338-
actx_error(actx, "unknown libcurl socket operation: %d", what);
1343+
actx_error_internal(actx, "unknown libcurl socket operation: %d", what);
13391344
return -1;
13401345
}
13411346

@@ -1345,7 +1350,7 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
13451350
res = kevent(actx->mux, ev, nev, ev_out, nev, &timeout);
13461351
if (res < 0)
13471352
{
1348-
actx_error(actx, "could not modify kqueue: %m");
1353+
actx_error_internal(actx, "could not modify kqueue: %m");
13491354
return -1;
13501355
}
13511356

@@ -1369,10 +1374,10 @@ register_socket(CURL *curl, curl_socket_t socket, int what, void *ctx,
13691374
switch (what)
13701375
{
13711376
case CURL_POLL_REMOVE:
1372-
actx_error(actx, "could not delete from kqueue: %m");
1377+
actx_error_internal(actx, "could not delete from kqueue: %m");
13731378
break;
13741379
default:
1375-
actx_error(actx, "could not add to kqueue: %m");
1380+
actx_error_internal(actx, "could not add to kqueue: %m");
13761381
}
13771382
return -1;
13781383
}
@@ -1421,7 +1426,7 @@ comb_multiplexer(struct async_ctx *actx)
14211426
*/
14221427
if (kevent(actx->mux, NULL, 0, &ev, 1, &timeout) < 0)
14231428
{
1424-
actx_error(actx, "could not comb kqueue: %m");
1429+
actx_error_internal(actx, "could not comb kqueue: %m");
14251430
return false;
14261431
}
14271432

@@ -1471,7 +1476,7 @@ set_timer(struct async_ctx *actx, long timeout)
14711476

14721477
if (timerfd_settime(actx->timerfd, 0 /* no flags */ , &spec, NULL) < 0)
14731478
{
1474-
actx_error(actx, "setting timerfd to %ld: %m", timeout);
1479+
actx_error_internal(actx, "setting timerfd to %ld: %m", timeout);
14751480
return false;
14761481
}
14771482

@@ -1501,14 +1506,14 @@ set_timer(struct async_ctx *actx, long timeout)
15011506
EV_SET(&ev, 1, EVFILT_TIMER, EV_DELETE, 0, 0, 0);
15021507
if (kevent(actx->timerfd, &ev, 1, NULL, 0, NULL) < 0 && errno != ENOENT)
15031508
{
1504-
actx_error(actx, "deleting kqueue timer: %m");
1509+
actx_error_internal(actx, "deleting kqueue timer: %m");
15051510
return false;
15061511
}
15071512

15081513
EV_SET(&ev, actx->timerfd, EVFILT_READ, EV_DELETE, 0, 0, 0);
15091514
if (kevent(actx->mux, &ev, 1, NULL, 0, NULL) < 0 && errno != ENOENT)
15101515
{
1511-
actx_error(actx, "removing kqueue timer from multiplexer: %m");
1516+
actx_error_internal(actx, "removing kqueue timer from multiplexer: %m");
15121517
return false;
15131518
}
15141519

@@ -1519,14 +1524,14 @@ set_timer(struct async_ctx *actx, long timeout)
15191524
EV_SET(&ev, 1, EVFILT_TIMER, (EV_ADD | EV_ONESHOT), 0, timeout, 0);
15201525
if (kevent(actx->timerfd, &ev, 1, NULL, 0, NULL) < 0)
15211526
{
1522-
actx_error(actx, "setting kqueue timer to %ld: %m", timeout);
1527+
actx_error_internal(actx, "setting kqueue timer to %ld: %m", timeout);
15231528
return false;
15241529
}
15251530

15261531
EV_SET(&ev, actx->timerfd, EVFILT_READ, EV_ADD, 0, 0, 0);
15271532
if (kevent(actx->mux, &ev, 1, NULL, 0, NULL) < 0)
15281533
{
1529-
actx_error(actx, "adding kqueue timer to multiplexer: %m");
1534+
actx_error_internal(actx, "adding kqueue timer to multiplexer: %m");
15301535
return false;
15311536
}
15321537

0 commit comments

Comments
 (0)