Repository: incubator-hawq Updated Branches: refs/heads/master c09ac9259 -> 8b13c4bae
HAWQ-1378. Elaborate the "invalid command-line arguments for server process" error. This patch mostly follows the pg commit below. commit 86947e666d39229558311d7b0be45608fd071ed8 Author: Peter Eisentraut <[email protected]> Date: Sun Mar 11 01:52:05 2012 +0200 Add more detail to error message for invalid arguments for server process It now prints the argument that was at fault. Also fix a small misbehavior where the error message issued by getopt() would complain about a program named "--single", because that's what argv[0] is in the server process. Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/8b13c4ba Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/8b13c4ba Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/8b13c4ba Branch: refs/heads/master Commit: 8b13c4bae2af3b06395b0b93e822c1d46caec4e9 Parents: c09ac92 Author: Paul Guo <[email protected]> Authored: Mon Mar 6 15:36:08 2017 +0800 Committer: Paul Guo <[email protected]> Committed: Wed Mar 15 13:12:18 2017 +0800 ---------------------------------------------------------------------- src/backend/tcop/postgres.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/8b13c4ba/src/backend/tcop/postgres.c ---------------------------------------------------------------------- diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 2450136..c1b4b02 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -4181,6 +4181,9 @@ PostgresMain(int argc, char *argv[], const char *username) errs++; break; } + + if (errs) + break; } /* @@ -4324,14 +4327,24 @@ PostgresMain(int argc, char *argv[], const char *username) if (IsUnderPostmaster) { /* noninteractive case: nothing should be left after switches */ - if (errs || argc != optind || dbname == NULL) + if (errs || argc != optind) { + if (errs) + optind--; /* complain about the previous argument */ + ereport(FATAL, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("invalid command-line arguments for server process"), + errmsg("invalid command-line argument for server process: %s", argv[optind]), errhint("Try \"%s --help\" for more information.", argv[0]))); } + if (dbname == NULL) + { + ereport(FATAL, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("%s: no database specified", argv[0]))); + } + BaseInit(); } else @@ -4339,10 +4352,13 @@ PostgresMain(int argc, char *argv[], const char *username) /* interactive case: database name can be last arg on command line */ if (errs || argc - optind > 1) { + if (errs) + optind--; /* complain about the previous argument */ + ereport(FATAL, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("%s: invalid command-line arguments", - argv[0]), + errmsg("%s: invalid command-line argument: %s", + argv[0], argv[optind]), errhint("Try \"%s --help\" for more information.", argv[0]))); } else if (argc - optind == 1)
