Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "extensions/renderer/api_invocation_errors.h" | |
| 6 | |
| 7 #include "base/strings/stringprintf.h" | |
| 8 | |
| 9 namespace extensions { | |
| 10 namespace api_errors { | |
| 11 | |
| 12 const char kTypeString[] = "string"; | |
| 13 const char kTypeDouble[] = "number"; | |
| 14 const char kTypeBoolean[] = "boolean"; | |
| 15 const char kTypeInteger[] = "integer"; | |
| 16 const char kTypeObject[] = "object"; | |
| 17 const char kTypeList[] = "array"; | |
| 18 const char kTypeBinary[] = "binary"; | |
| 19 const char kTypeFunction[] = "function"; | |
| 20 const char kTypeUndefined[] = "undefined"; | |
| 21 const char kTypeNull[] = "null"; | |
| 22 | |
| 23 const char kInvalidEnumValue[] = "Value must be one of %s."; | |
| 24 const char kMissingRequiredProperty[] = "Missing required property '%s'."; | |
| 25 const char kUnexpectedProperty[] = "Unexpected property: '%s'."; | |
| 26 const char kTooFewArrayItems[] = "Array must have at least %d items."; | |
| 27 const char kTooManyArrayItems[] = "Array must have at most %d items."; | |
| 28 const char kTooFewStringChars[] = "String must have at least %d characters."; | |
| 29 const char kTooManyStringChars[] = "String must have at most %d characters."; | |
| 30 const char kNumberTooSmall[] = "Value must be at least %d."; | |
| 31 const char kNumberTooLarge[] = "Value must be at most %d."; | |
| 32 const char kInvalidType[] = "Invalid type: expected %s, found %s."; | |
| 33 const char kNotAnInstance[] = "Value must be an instance of %s."; | |
| 34 const char kInvalidChoice[] = "Value did not match any choice."; | |
| 35 const char kUnserializableValue[] = "Value is unserializable."; | |
| 36 const char kScriptThrewError[] = "Script threw an error."; | |
| 37 | |
| 38 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
| |
| 39 return base::StringPrintf(error, placeholder); | |
| 40 } | |
| 41 | |
| 42 std::string GetError(const char* error, const char* placeholder) { | |
| 43 return base::StringPrintf(error, placeholder); | |
| 44 } | |
| 45 | |
| 46 std::string GetError(const char* error, | |
| 47 const char* placeholder1, | |
| 48 const char* placeholder2) { | |
| 49 return base::StringPrintf(error, placeholder1, placeholder2); | |
| 50 } | |
| 51 | |
| 52 std::string GetIndexError(uint32_t index, base::StringPiece error) { | |
| 53 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
| |
| 54 } | |
| 55 | |
| 56 std::string GetPropertyError(base::StringPiece property_name, | |
| 57 base::StringPiece error) { | |
| 58 return base::StringPrintf("Error at property '%s': %s", property_name.data(), | |
| 59 error.data()); | |
| 60 } | |
| 61 | |
| 62 } // namespace api_errors | |
| 63 } // namespace extensions | |
| OLD | NEW |