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..c82f11474a04a3b1835604e6e662c558725d34e4 |
| --- /dev/null |
| +++ b/extensions/renderer/api_invocation_errors.cc |
| @@ -0,0 +1,63 @@ |
| +// 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 "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"; |
| + |
| +const char kInvalidEnumValue[] = "Value must be one of %s."; |
| +const char kMissingRequiredProperty[] = "Missing required property '%s'."; |
| +const char kUnexpectedProperty[] = "Unexpected property: '%s'."; |
| +const char kTooFewArrayItems[] = "Array must have at least %d items."; |
| +const char kTooManyArrayItems[] = "Array must have at most %d items."; |
| +const char kTooFewStringChars[] = "String must have at least %d characters."; |
| +const char kTooManyStringChars[] = "String must have at most %d characters."; |
| +const char kNumberTooSmall[] = "Value must be at least %d."; |
| +const char kNumberTooLarge[] = "Value must be at most %d."; |
| +const char kInvalidType[] = "Invalid type: expected %s, found %s."; |
| +const char kNotAnInstance[] = "Value must be an instance of %s."; |
| +const char kInvalidChoice[] = "Value did not match any choice."; |
| +const char kUnserializableValue[] = "Value is unserializable."; |
| +const char kScriptThrewError[] = "Script threw an error."; |
| + |
| +std::string GetError(const char* error, int placeholder) { |
|
jbroman
2017/04/25 15:44:55
Hmm, my main question about this is that it's not
Devlin
2017/04/25 22:47:59
Good idea! I was a little worried about the exces
|
| + return base::StringPrintf(error, placeholder); |
| +} |
| + |
| +std::string GetError(const char* error, const char* placeholder) { |
| + return base::StringPrintf(error, placeholder); |
| +} |
| + |
| +std::string GetError(const char* error, |
| + const char* placeholder1, |
| + const char* placeholder2) { |
| + return base::StringPrintf(error, placeholder1, placeholder2); |
| +} |
| + |
| +std::string GetIndexError(uint32_t index, base::StringPiece error) { |
| + return base::StringPrintf("Error at index %u: %s", index, error.data()); |
|
jbroman
2017/04/25 15:44:55
You can't pass base::StringPiece to fill %s in pri
Devlin
2017/04/25 22:47:59
Good catch! Opted for using std::strings for the
|
| +} |
| + |
| +std::string GetPropertyError(base::StringPiece property_name, |
| + base::StringPiece error) { |
| + return base::StringPrintf("Error at property '%s': %s", property_name.data(), |
| + error.data()); |
| +} |
| + |
| +} // namespace api_errors |
| +} // namespace extensions |