Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9a374b7

Browse files
committed
Improve frontend error logging style.
Get rid of the separate "FATAL" log level, as it was applied so inconsistently as to be meaningless. This mostly involves s/pg_log_fatal/pg_log_error/g. Create a macro pg_fatal() to handle the common use-case of pg_log_error() immediately followed by exit(1). Various modules had already invented either this or equivalent macros; standardize on pg_fatal() and apply it where possible. Invent the ability to add "detail" and "hint" messages to a frontend message, much as we have long had in the backend. Except where rewording was needed to convert existing coding to detail/hint style, I have (mostly) resisted the temptation to change existing message wording. Patch by me. Design and patch reviewed at various stages by Robert Haas, Kyotaro Horiguchi, Peter Eisentraut and Daniel Gustafsson. Discussion: https://postgr.es/m/1363732.1636496441@sss.pgh.pa.us
1 parent 5c431c7 commit 9a374b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1367
-2395
lines changed

contrib/oid2name/oid2name.c

+10-12
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,17 @@ get_opts(int argc, char **argv, struct options *my_opts)
182182
break;
183183

184184
default:
185-
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
185+
/* getopt_long already emitted a complaint */
186+
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
186187
exit(1);
187188
}
188189
}
189190

190191
if (optind < argc)
191192
{
192-
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
193-
progname, argv[optind]);
194-
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
193+
pg_log_error("too many command-line arguments (first is \"%s\")",
194+
argv[optind]);
195+
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
195196
exit(1);
196197
}
197198
}
@@ -328,11 +329,8 @@ sql_conn(struct options *my_opts)
328329
conn = PQconnectdbParams(keywords, values, true);
329330

330331
if (!conn)
331-
{
332-
pg_log_error("could not connect to database %s",
333-
my_opts->dbname);
334-
exit(1);
335-
}
332+
pg_fatal("could not connect to database %s",
333+
my_opts->dbname);
336334

337335
if (PQstatus(conn) == CONNECTION_BAD &&
338336
PQconnectionNeedsPassword(conn) &&
@@ -359,7 +357,7 @@ sql_conn(struct options *my_opts)
359357
PQerrorMessage(conn));
360358
PQclear(res);
361359
PQfinish(conn);
362-
exit(-1);
360+
exit(1);
363361
}
364362
PQclear(res);
365363

@@ -390,11 +388,11 @@ sql_exec(PGconn *conn, const char *todo, bool quiet)
390388
if (!res || PQresultStatus(res) > 2)
391389
{
392390
pg_log_error("query failed: %s", PQerrorMessage(conn));
393-
pg_log_error("query was: %s", todo);
391+
pg_log_error_detail("Query was: %s", todo);
394392

395393
PQclear(res);
396394
PQfinish(conn);
397-
exit(-1);
395+
exit(1);
398396
}
399397

400398
/* get the number of fields */

contrib/vacuumlo/vacuumlo.c

+5-13
Original file line numberDiff line numberDiff line change
@@ -492,19 +492,13 @@ main(int argc, char **argv)
492492
{
493493
switch (c)
494494
{
495-
case '?':
496-
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
497-
exit(1);
498495
case 'h':
499496
param.pg_host = pg_strdup(optarg);
500497
break;
501498
case 'l':
502499
param.transaction_limit = strtol(optarg, NULL, 10);
503500
if (param.transaction_limit < 0)
504-
{
505-
pg_log_error("transaction limit must not be negative (0 disables)");
506-
exit(1);
507-
}
501+
pg_fatal("transaction limit must not be negative (0 disables)");
508502
break;
509503
case 'n':
510504
param.dry_run = 1;
@@ -513,10 +507,7 @@ main(int argc, char **argv)
513507
case 'p':
514508
port = strtol(optarg, NULL, 10);
515509
if ((port < 1) || (port > 65535))
516-
{
517-
pg_log_error("invalid port number: %s", optarg);
518-
exit(1);
519-
}
510+
pg_fatal("invalid port number: %s", optarg);
520511
param.pg_port = pg_strdup(optarg);
521512
break;
522513
case 'U':
@@ -532,7 +523,8 @@ main(int argc, char **argv)
532523
param.pg_prompt = TRI_YES;
533524
break;
534525
default:
535-
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
526+
/* getopt_long already emitted a complaint */
527+
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
536528
exit(1);
537529
}
538530
}
@@ -541,7 +533,7 @@ main(int argc, char **argv)
541533
if (optind >= argc)
542534
{
543535
pg_log_error("missing required argument: database name");
544-
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
536+
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
545537
exit(1);
546538
}
547539

0 commit comments

Comments
 (0)