Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Side by Side Diff: extensions/renderer/api_invocation_errors.cc

Issue 2947463002: [Extensions Bindings] Add a bindings/ subdirectory under renderer (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 const char kTypeAny[] = "any";
26
27 std::string InvalidEnumValue(const std::set<std::string>& valid_enums) {
28 std::vector<base::StringPiece> options(valid_enums.begin(),
29 valid_enums.end());
30 std::string options_str = base::JoinString(options, ", ");
31 return base::StringPrintf("Value must be one of %s.", options_str.c_str());
32 }
33
34 std::string MissingRequiredProperty(const char* property_name) {
35 return base::StringPrintf("Missing required property '%s'.", property_name);
36 }
37
38 std::string UnexpectedProperty(const char* property_name) {
39 return base::StringPrintf("Unexpected property: '%s'.", property_name);
40 }
41
42 std::string TooFewArrayItems(int minimum, int found) {
43 return base::StringPrintf("Array must have at least %d items; found %d.",
44 minimum, found);
45 }
46
47 std::string TooManyArrayItems(int maximum, int found) {
48 return base::StringPrintf("Array must have at most %d items; found %d.",
49 maximum, found);
50 }
51
52 std::string TooFewStringChars(int minimum, int found) {
53 return base::StringPrintf(
54 "String must have at least %d characters; found %d.", minimum, found);
55 }
56
57 std::string TooManyStringChars(int maximum, int found) {
58 return base::StringPrintf("String must have at most %d characters; found %d.",
59 maximum, found);
60 }
61
62 std::string NumberTooSmall(int minimum) {
63 return base::StringPrintf("Value must be at least %d.", minimum);
64 }
65
66 std::string NumberTooLarge(int maximum) {
67 return base::StringPrintf("Value must be at most %d.", maximum);
68 }
69
70 std::string InvalidType(const char* expected_type, const char* actual_type) {
71 return base::StringPrintf("Invalid type: expected %s, found %s.",
72 expected_type, actual_type);
73 }
74
75 std::string NotAnInstance(const char* instance_type) {
76 return base::StringPrintf("Value must be an instance of %s.", instance_type);
77 }
78
79 std::string InvalidChoice() {
80 return "Value did not match any choice.";
81 }
82
83 std::string UnserializableValue() {
84 return "Value is unserializable.";
85 }
86
87 std::string ScriptThrewError() {
88 return "Script threw an error.";
89 }
90
91 std::string TooManyArguments() {
92 return "Too many arguments.";
93 }
94
95 std::string MissingRequiredArgument(const char* argument_name) {
96 return base::StringPrintf("Missing required argument '%s'.", argument_name);
97 }
98
99 std::string IndexError(uint32_t index, const std::string& error) {
100 return base::StringPrintf("Error at index %u: %s", index, error.c_str());
101 }
102
103 std::string PropertyError(const char* property_name, const std::string& error) {
104 return base::StringPrintf("Error at property '%s': %s", property_name,
105 error.c_str());
106 }
107
108 std::string ArgumentError(const std::string& parameter_name,
109 const std::string& error) {
110 return base::StringPrintf("Error at parameter '%s': %s",
111 parameter_name.c_str(), error.c_str());
112 }
113
114 std::string InvocationError(const std::string& method_name,
115 const std::string& expected_signature,
116 const std::string& error) {
117 return base::StringPrintf("Error in invocation of %s(%s): %s",
118 method_name.c_str(), expected_signature.c_str(),
119 error.c_str());
120 }
121
122 } // namespace api_errors
123 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/api_invocation_errors.h ('k') | extensions/renderer/api_invocation_errors_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698