Chromium Code Reviews| Index: extensions/renderer/api_invocation_errors.cc |
| diff --git a/extensions/renderer/api_invocation_errors.cc b/extensions/renderer/api_invocation_errors.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bc0799dc41cf61e5fd7e7a5e7a77bc3de2258fde |
| --- /dev/null |
| +++ b/extensions/renderer/api_invocation_errors.cc |
| @@ -0,0 +1,97 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "extensions/renderer/api_invocation_errors.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/strings/string_util.h" |
| +#include "base/strings/stringprintf.h" |
| + |
| +namespace extensions { |
| +namespace api_errors { |
| + |
| +const char kTypeString[] = "string"; |
| +const char kTypeDouble[] = "number"; |
| +const char kTypeBoolean[] = "boolean"; |
| +const char kTypeInteger[] = "integer"; |
| +const char kTypeObject[] = "object"; |
| +const char kTypeList[] = "array"; |
| +const char kTypeBinary[] = "binary"; |
| +const char kTypeFunction[] = "function"; |
| +const char kTypeUndefined[] = "undefined"; |
| +const char kTypeNull[] = "null"; |
| + |
| +std::string InvalidEnumValue(const std::set<std::string>& valid_enums) { |
| + std::vector<base::StringPiece> options(valid_enums.begin(), |
| + valid_enums.end()); |
| + std::string options_str = base::JoinString(options, ", "); |
| + return base::StringPrintf("Value must be one of %s.", options_str.c_str()); |
| +} |
| + |
| +std::string MissingRequiredProperty(const char* property_name) { |
| + return base::StringPrintf("Missing required property '%s'.", property_name); |
| +} |
| + |
| +std::string UnexpectedProperty(const char* property_name) { |
| + return base::StringPrintf("Unexpected property: '%s'.", property_name); |
| +} |
| + |
| +std::string TooFewArrayItems(int minimum) { |
| + return base::StringPrintf("Array must have at least %d items.", minimum); |
| +} |
| + |
| +std::string TooManyArrayItems(int maximum) { |
| + return base::StringPrintf("Array must have at most %d items.", maximum); |
| +} |
| + |
| +std::string TooFewStringChars(int minimum) { |
| + return base::StringPrintf("String must have at least %d characters.", |
| + minimum); |
| +} |
| + |
| +std::string TooManyStringChars(int maximum) { |
| + return base::StringPrintf("String must have at most %d characters.", maximum); |
| +} |
| + |
| +std::string NumberTooSmall(int minimum) { |
| + return base::StringPrintf("Value must be at least %d.", minimum); |
| +} |
| + |
| +std::string NumberTooLarge(int maximum) { |
| + return base::StringPrintf("Value must be at most %d.", maximum); |
| +} |
| + |
| +std::string InvalidType(const char* expected_type, const char* actual_type) { |
| + return base::StringPrintf("Invalid type: expected %s, found %s.", |
| + expected_type, actual_type); |
| +} |
| + |
| +std::string NotAnInstance(const char* instance_type) { |
| + return base::StringPrintf("Value must be an instance of %s.", instance_type); |
| +} |
| + |
| +std::string InvalidChoice() { |
| + return base::StringPrintf("Value did not match any choice."); |
|
jbroman
2017/04/26 14:34:26
nit: no need for StringPrintf when there are no %
Devlin
2017/04/26 16:18:26
Whoops! Thanks. Find-replace fail.
|
| +} |
| + |
| +std::string UnserializableValue() { |
| + return base::StringPrintf("Value is unserializable."); |
| +} |
| + |
| +std::string ScriptThrewError() { |
| + return base::StringPrintf("Script threw an error."); |
| +} |
| + |
| +std::string IndexError(uint32_t index, const std::string& error) { |
| + return base::StringPrintf("Error at index %u: %s", index, error.c_str()); |
| +} |
| + |
| +std::string PropertyError(const char* property_name, const std::string& error) { |
| + return base::StringPrintf("Error at property '%s': %s", property_name, |
| + error.c_str()); |
| +} |
| + |
| +} // namespace api_errors |
| +} // namespace extensions |