Merge "init: use Errorf() now that we have it"

This commit is contained in:
Tom Cherry 2019-06-17 14:42:20 +00:00 committed by Gerrit Code Review
commit 30f6f42c04
5 changed files with 14 additions and 23 deletions

View File

@ -29,7 +29,6 @@
#include <vector>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <gtest/gtest.h>

View File

@ -14,14 +14,11 @@
* limitations under the License.
*/
#ifndef _INIT_KEYWORD_MAP_H_
#define _INIT_KEYWORD_MAP_H_
#pragma once
#include <map>
#include <string>
#include <android-base/stringprintf.h>
#include "result.h"
namespace android {
@ -37,8 +34,6 @@ class KeywordMap {
}
const Result<Function> FindFunction(const std::vector<std::string>& args) const {
using android::base::StringPrintf;
if (args.empty()) return Error() << "Keyword needed, but not provided";
auto& keyword = args[0];
@ -46,7 +41,7 @@ class KeywordMap {
auto function_info_it = map().find(keyword);
if (function_info_it == map().end()) {
return Error() << StringPrintf("Invalid keyword '%s'", keyword.c_str());
return Errorf("Invalid keyword '{}'", keyword);
}
auto function_info = function_info_it->second;
@ -54,17 +49,17 @@ class KeywordMap {
auto min_args = std::get<0>(function_info);
auto max_args = std::get<1>(function_info);
if (min_args == max_args && num_args != min_args) {
return Error() << StringPrintf("%s requires %zu argument%s", keyword.c_str(), min_args,
(min_args > 1 || min_args == 0) ? "s" : "");
return Errorf("{} requires {} argument{}", keyword, min_args,
(min_args > 1 || min_args == 0) ? "s" : "");
}
if (num_args < min_args || num_args > max_args) {
if (max_args == std::numeric_limits<decltype(max_args)>::max()) {
return Error() << StringPrintf("%s requires at least %zu argument%s",
keyword.c_str(), min_args, min_args > 1 ? "s" : "");
return Errorf("{} requires at least {} argument{}", keyword, min_args,
min_args > 1 ? "s" : "");
} else {
return Error() << StringPrintf("%s requires between %zu and %zu arguments",
keyword.c_str(), min_args, max_args);
return Errorf("{} requires between {} and {} arguments", keyword, min_args,
max_args);
}
}
@ -79,5 +74,3 @@ class KeywordMap {
} // namespace init
} // namespace android
#endif

View File

@ -41,7 +41,6 @@
#include <android-base/logging.h>
#include <android-base/macros.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <bootloader_message/bootloader_message.h>
@ -62,7 +61,6 @@
using android::base::GetBoolProperty;
using android::base::Split;
using android::base::StringPrintf;
using android::base::Timer;
using android::base::unique_fd;
using android::base::WriteStringToFile;

View File

@ -22,6 +22,8 @@
#include <android-base/result.h>
using android::base::ErrnoError;
using android::base::ErrnoErrorf;
using android::base::Error;
using android::base::Errorf;
using android::base::Result;
using android::base::ResultError;

View File

@ -332,12 +332,11 @@ Result<void> Service::ParseCapabilities(std::vector<std::string>&& args) {
const std::string& arg = args[i];
int res = LookupCap(arg);
if (res < 0) {
return Error() << StringPrintf("invalid capability '%s'", arg.c_str());
return Errorf("invalid capability '{}'", arg);
}
unsigned int cap = static_cast<unsigned int>(res); // |res| is >= 0.
if (cap > last_valid_cap) {
return Error() << StringPrintf("capability '%s' not supported by the kernel",
arg.c_str());
return Errorf("capability '{}' not supported by the kernel", arg);
}
(*capabilities_)[cap] = true;
}
@ -402,8 +401,8 @@ Result<void> Service::ParsePriority(std::vector<std::string>&& args) {
if (!ParseInt(args[1], &proc_attr_.priority,
static_cast<int>(ANDROID_PRIORITY_HIGHEST), // highest is negative
static_cast<int>(ANDROID_PRIORITY_LOWEST))) {
return Error() << StringPrintf("process priority value must be range %d - %d",
ANDROID_PRIORITY_HIGHEST, ANDROID_PRIORITY_LOWEST);
return Errorf("process priority value must be range {} - {}", ANDROID_PRIORITY_HIGHEST,
ANDROID_PRIORITY_LOWEST);
}
return {};
}