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 <vector> | |
8 | |
9 #include "base/strings/string_util.h" | |
10 #include "base/strings/stringprintf.h" | |
11 | |
12 namespace extensions { | |
13 namespace api_errors { | |
14 | |
15 const char kTypeString[] = "string"; | |
16 const char kTypeDouble[] = "number"; | |
17 const char kTypeBoolean[] = "boolean"; | |
18 const char kTypeInteger[] = "integer"; | |
19 const char kTypeObject[] = "object"; | |
20 const char kTypeList[] = "array"; | |
21 const char kTypeBinary[] = "binary"; | |
22 const char kTypeFunction[] = "function"; | |
23 const char kTypeUndefined[] = "undefined"; | |
24 const char kTypeNull[] = "null"; | |
25 | |
26 std::string InvalidEnumValue(const std::set<std::string>& valid_enums) { | |
27 std::vector<base::StringPiece> options(valid_enums.begin(), | |
28 valid_enums.end()); | |
29 std::string options_str = base::JoinString(options, ", "); | |
30 return base::StringPrintf("Value must be one of %s.", options_str.c_str()); | |
31 } | |
32 | |
33 std::string MissingRequiredProperty(const char* property_name) { | |
34 return base::StringPrintf("Missing required property '%s'.", property_name); | |
35 } | |
36 | |
37 std::string UnexpectedProperty(const char* property_name) { | |
38 return base::StringPrintf("Unexpected property: '%s'.", property_name); | |
39 } | |
40 | |
41 std::string TooFewArrayItems(int minimum) { | |
42 return base::StringPrintf("Array must have at least %d items.", minimum); | |
43 } | |
44 | |
45 std::string TooManyArrayItems(int maximum) { | |
46 return base::StringPrintf("Array must have at most %d items.", maximum); | |
47 } | |
48 | |
49 std::string TooFewStringChars(int minimum) { | |
50 return base::StringPrintf("String must have at least %d characters.", | |
51 minimum); | |
52 } | |
53 | |
54 std::string TooManyStringChars(int maximum) { | |
55 return base::StringPrintf("String must have at most %d characters.", maximum); | |
56 } | |
57 | |
58 std::string NumberTooSmall(int minimum) { | |
59 return base::StringPrintf("Value must be at least %d.", minimum); | |
60 } | |
61 | |
62 std::string NumberTooLarge(int maximum) { | |
63 return base::StringPrintf("Value must be at most %d.", maximum); | |
64 } | |
65 | |
66 std::string InvalidType(const char* expected_type, const char* actual_type) { | |
67 return base::StringPrintf("Invalid type: expected %s, found %s.", | |
68 expected_type, actual_type); | |
69 } | |
70 | |
71 std::string NotAnInstance(const char* instance_type) { | |
72 return base::StringPrintf("Value must be an instance of %s.", instance_type); | |
73 } | |
74 | |
75 std::string InvalidChoice() { | |
76 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.
| |
77 } | |
78 | |
79 std::string UnserializableValue() { | |
80 return base::StringPrintf("Value is unserializable."); | |
81 } | |
82 | |
83 std::string ScriptThrewError() { | |
84 return base::StringPrintf("Script threw an error."); | |
85 } | |
86 | |
87 std::string IndexError(uint32_t index, const std::string& error) { | |
88 return base::StringPrintf("Error at index %u: %s", index, error.c_str()); | |
89 } | |
90 | |
91 std::string PropertyError(const char* property_name, const std::string& error) { | |
92 return base::StringPrintf("Error at property '%s': %s", property_name, | |
93 error.c_str()); | |
94 } | |
95 | |
96 } // namespace api_errors | |
97 } // namespace extensions | |
OLD | NEW |