Improve some error messages.
It's rude not to say _what_ you couldn't understand, and it's confusing
not to _quote_ what you couldn't understand.
Bug: https://issuetracker.google.com/286968214
Test: adb logcat --pid ''
Change-Id: Ifa04f8c64cacc4734d24291eebf0dff3a5c4b941
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index e8b5b8d..a60e353 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -601,8 +601,7 @@
}
if (!ParseUint(optarg, &pid) || pid < 1) {
- error(EXIT_FAILURE, 0, "%s %s out of range.",
- long_options[option_index].name, optarg);
+ error(EXIT_FAILURE, 0, "pid '%s' out of range.", optarg);
}
break;
}
@@ -611,13 +610,11 @@
// ToDo: implement API that supports setting a wrap timeout
size_t timeout = ANDROID_LOG_WRAP_DEFAULT_TIMEOUT;
if (optarg && (!ParseUint(optarg, &timeout) || timeout < 1)) {
- error(EXIT_FAILURE, 0, "%s %s out of range.",
- long_options[option_index].name, optarg);
+ error(EXIT_FAILURE, 0, "wrap timeout '%s' out of range.", optarg);
}
if (timeout != ANDROID_LOG_WRAP_DEFAULT_TIMEOUT) {
- fprintf(stderr, "WARNING: %s %u seconds, ignoring %zu\n",
- long_options[option_index].name, ANDROID_LOG_WRAP_DEFAULT_TIMEOUT,
- timeout);
+ fprintf(stderr, "WARNING: wrap timeout %zus, not default %us\n", timeout,
+ ANDROID_LOG_WRAP_DEFAULT_TIMEOUT);
}
break;
}
@@ -735,8 +732,7 @@
} else {
log_id_t log_id = android_name_to_log_id(buffer.c_str());
if (log_id >= LOG_ID_MAX) {
- error(EXIT_FAILURE, 0, "Unknown buffer '%s' listed for -b.",
- buffer.c_str());
+ error(EXIT_FAILURE, 0, "Unknown -b buffer '%s'.", buffer.c_str());
}
if (log_id == LOG_ID_SECURITY) {
security_buffer_selected = true;
@@ -760,13 +756,13 @@
case 'r':
if (!ParseUint(optarg, &log_rotate_size_kb_) || log_rotate_size_kb_ < 1) {
- error(EXIT_FAILURE, 0, "Invalid parameter '%s' to -r.", optarg);
+ error(EXIT_FAILURE, 0, "Invalid -r '%s'.", optarg);
}
break;
case 'n':
if (!ParseUint(optarg, &max_rotated_logs_) || max_rotated_logs_ < 1) {
- error(EXIT_FAILURE, 0, "Invalid parameter '%s' to -n.", optarg);
+ error(EXIT_FAILURE, 0, "Invalid -n '%s'.", optarg);
}
break;
@@ -774,7 +770,7 @@
for (const auto& arg : Split(optarg, delimiters)) {
int err = SetLogFormat(arg.c_str());
if (err < 0) {
- error(EXIT_FAILURE, 0, "Invalid parameter '%s' to -v.", arg.c_str());
+ error(EXIT_FAILURE, 0, "Invalid -v '%s'.", arg.c_str());
}
if (err) hasSetLogFormat = true;
}
@@ -859,7 +855,8 @@
if (forceFilters.size()) {
int err = android_log_addFilterString(logformat_.get(), forceFilters.c_str());
if (err < 0) {
- error(EXIT_FAILURE, 0, "Invalid filter expression in logcat args.");
+ error(EXIT_FAILURE, 0, "Invalid filter expression '%s' in logcat args.",
+ forceFilters.c_str());
}
} else if (argc == optind) {
// Add from environment variable
@@ -869,7 +866,8 @@
int err = android_log_addFilterString(logformat_.get(), env_tags_orig);
if (err < 0) {
- error(EXIT_FAILURE, 0, "Invalid filter expression in ANDROID_LOG_TAGS.");
+ error(EXIT_FAILURE, 0, "Invalid filter expression '%s' in ANDROID_LOG_TAGS.",
+ env_tags_orig);
}
}
} else {
@@ -1006,7 +1004,7 @@
if (setPruneList) {
size_t len = strlen(setPruneList);
if (android_logger_set_prune_list(logger_list.get(), setPruneList, len)) {
- error(EXIT_FAILURE, 0, "Failed to set the prune list.");
+ error(EXIT_FAILURE, 0, "Failed to set the prune list to '%s'.", setPruneList);
}
return EXIT_SUCCESS;
}