Commit 79706fd3 authored by Tony Chen's avatar Tony Chen Committed by Daniel Black

Minor improvements to options error handling

- Add additional MTRs for more coverage on invalid options
- Updating a few error messages to be more informative
- Use the exit code from handle_options() when there is an error processing
  user options

All new code of the whole pull request, including one or several files that are
either new files or modified ones, are contributed under the BSD-new license. I
am contributing on behalf of my employer Amazon Web Services, Inc.
parent 47d75cdd
...@@ -11,8 +11,10 @@ Test to see if multiple ambiguous options and invalid arguments will be displaye ...@@ -11,8 +11,10 @@ Test to see if multiple ambiguous options and invalid arguments will be displaye
FOUND 1 /Error while setting value 'invalid_value' to 'sql_mode'/ in mysqltest.log FOUND 1 /Error while setting value 'invalid_value' to 'sql_mode'/ in mysqltest.log
FOUND 1 /ambiguous option '--character'/ in mysqltest.log FOUND 1 /ambiguous option '--character'/ in mysqltest.log
FOUND 1 /option '--bootstrap' cannot take an argument/ in mysqltest.log FOUND 1 /option '--bootstrap' cannot take an argument/ in mysqltest.log
FOUND 1 /Incorrect integer value: '18446744073709551616'/ in mysqltest.log FOUND 1 /Integer value out of range for uint64: '18446744073709551616'/ in mysqltest.log
FOUND 1 /Error while setting value '18446744073709551616' to 'binlog_cache_size'/ in mysqltest.log FOUND 1 /Error while setting value '18446744073709551616' to 'binlog_cache_size'/ in mysqltest.log
FOUND 1 /Unknown suffix 'y' used for variable 'bulk_insert_buffer_size' \(value '123y'\). Legal suffix characters are: K, M, G, T, P, E/ in mysqltest.log
FOUND 1 /Error while setting value '123y' to 'bulk_insert_buffer_size'/ in mysqltest.log
Test that --help --verbose works Test that --help --verbose works
Test that --not-known-option --help --verbose gives error Test that --not-known-option --help --verbose gives error
Done. Done.
...@@ -25,7 +25,7 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; ...@@ -25,7 +25,7 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err;
--echo Test bad binlog format. --echo Test bad binlog format.
--error 1 --error 13
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --log-bin --binlog-format=badformat >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 --exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --log-bin --binlog-format=badformat >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1
...@@ -35,7 +35,7 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; ...@@ -35,7 +35,7 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err;
--echo Test non-numeric value passed to number option. --echo Test non-numeric value passed to number option.
--error 1 --error 9
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --min-examined-row-limit=notanumber >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 --exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --min-examined-row-limit=notanumber >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1
...@@ -60,8 +60,8 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; ...@@ -60,8 +60,8 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err;
--source include/search_pattern_in_file.inc --source include/search_pattern_in_file.inc
--echo Test to see if multiple ambiguous options and invalid arguments will be displayed in the error output --echo Test to see if multiple ambiguous options and invalid arguments will be displayed in the error output
--error 1 --error 9
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob --binlog_cache_size=18446744073709551616 >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1 --exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/mysqld_option_err --skip-grant-tables --getopt-prefix-matching --sql-mode=invalid_value --character --bootstrap=partstoob --binlog_cache_size=18446744073709551616 --bulk_insert_buffer_size=123y >>$MYSQLTEST_VARDIR/tmp/mysqld_option_err/mysqltest.log 2>&1
--let SEARCH_PATTERN=Error while setting value 'invalid_value' to 'sql_mode' --let SEARCH_PATTERN=Error while setting value 'invalid_value' to 'sql_mode'
--source include/search_pattern_in_file.inc --source include/search_pattern_in_file.inc
...@@ -69,10 +69,14 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err; ...@@ -69,10 +69,14 @@ mkdir $MYSQLTEST_VARDIR/tmp/mysqld_option_err;
--source include/search_pattern_in_file.inc --source include/search_pattern_in_file.inc
--let SEARCH_PATTERN=option '--bootstrap' cannot take an argument --let SEARCH_PATTERN=option '--bootstrap' cannot take an argument
--source include/search_pattern_in_file.inc --source include/search_pattern_in_file.inc
--let SEARCH_PATTERN=Incorrect integer value: '18446744073709551616' --let SEARCH_PATTERN=Integer value out of range for uint64: '18446744073709551616'
--source include/search_pattern_in_file.inc --source include/search_pattern_in_file.inc
--let SEARCH_PATTERN=Error while setting value '18446744073709551616' to 'binlog_cache_size' --let SEARCH_PATTERN=Error while setting value '18446744073709551616' to 'binlog_cache_size'
--source include/search_pattern_in_file.inc --source include/search_pattern_in_file.inc
--let SEARCH_PATTERN=Unknown suffix 'y' used for variable 'bulk_insert_buffer_size' \(value '123y'\). Legal suffix characters are: K, M, G, T, P, E
--source include/search_pattern_in_file.inc
--let SEARCH_PATTERN=Error while setting value '123y' to 'bulk_insert_buffer_size'
--source include/search_pattern_in_file.inc
# #
# Test that an wrong option with --help --verbose gives an error # Test that an wrong option with --help --verbose gives an error
......
...@@ -858,7 +858,7 @@ static int setval(const struct my_option *opts, void *value, char *argument, ...@@ -858,7 +858,7 @@ static int setval(const struct my_option *opts, void *value, char *argument,
} }
if (err) if (err)
{ {
res= EXIT_UNKNOWN_SUFFIX; res= err;
goto ret; goto ret;
}; };
} }
...@@ -992,7 +992,7 @@ static inline ulonglong eval_num_suffix(char *suffix, int *error) ...@@ -992,7 +992,7 @@ static inline ulonglong eval_num_suffix(char *suffix, int *error)
case 'E': case 'E':
return 1ULL << 60; return 1ULL << 60;
default: default:
*error= 1; *error= EXIT_UNKNOWN_SUFFIX;
return 0ULL; return 0ULL;
} }
} }
...@@ -1018,14 +1018,15 @@ static longlong eval_num_suffix_ll(char *argument, ...@@ -1018,14 +1018,15 @@ static longlong eval_num_suffix_ll(char *argument,
if (errno == ERANGE) if (errno == ERANGE)
{ {
my_getopt_error_reporter(ERROR_LEVEL, my_getopt_error_reporter(ERROR_LEVEL,
"Incorrect integer value: '%s'", argument); "Integer value out of range for int64: '%s'", argument);
*error= 1; *error= EXIT_ARGUMENT_INVALID;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
num*= eval_num_suffix(endchar, error); num*= eval_num_suffix(endchar, error);
if (*error) if (*error)
fprintf(stderr, my_getopt_error_reporter(ERROR_LEVEL,
"Unknown suffix '%c' used for variable '%s' (value '%s')\n", "Unknown suffix '%c' used for variable '%s' (value '%s'). "
"Legal suffix characters are: K, M, G, T, P, E",
*endchar, option_name, argument); *endchar, option_name, argument);
DBUG_RETURN(num); DBUG_RETURN(num);
} }
...@@ -1050,14 +1051,15 @@ static ulonglong eval_num_suffix_ull(char *argument, ...@@ -1050,14 +1051,15 @@ static ulonglong eval_num_suffix_ull(char *argument,
if (errno == ERANGE) if (errno == ERANGE)
{ {
my_getopt_error_reporter(ERROR_LEVEL, my_getopt_error_reporter(ERROR_LEVEL,
"Incorrect integer value: '%s'", argument); "Integer value out of range for uint64: '%s'", argument);
*error= 1; *error= EXIT_ARGUMENT_INVALID;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
num*= eval_num_suffix(endchar, error); num*= eval_num_suffix(endchar, error);
if (*error) if (*error)
fprintf(stderr, my_getopt_error_reporter(ERROR_LEVEL,
"Unknown suffix '%c' used for variable '%s' (value '%s')\n", "Unknown suffix '%c' used for variable '%s' (value '%s'). "
"Legal suffix characters are: K, M, G, T, P, E",
*endchar, option_name, argument); *endchar, option_name, argument);
DBUG_RETURN(num); DBUG_RETURN(num);
} }
......
...@@ -3860,8 +3860,9 @@ static int init_common_variables() ...@@ -3860,8 +3860,9 @@ static int init_common_variables()
SQLCOM_END + 11); SQLCOM_END + 11);
#endif #endif
if (get_options(&remaining_argc, &remaining_argv)) int opt_err;
exit(1); if ((opt_err= get_options(&remaining_argc, &remaining_argv)))
exit(opt_err);
if (IS_SYSVAR_AUTOSIZE(&server_version_ptr)) if (IS_SYSVAR_AUTOSIZE(&server_version_ptr))
set_server_version(server_version, sizeof(server_version)); set_server_version(server_version, sizeof(server_version));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment