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

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

Issue 2837023003: [Extensions Bindings] Add argument parsing errors (Closed)
Patch Set: nits Created 3 years, 7 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
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, int found) {
42 return base::StringPrintf("Array must have at least %d items; found %d.",
43 minimum, found);
44 }
45
46 std::string TooManyArrayItems(int maximum, int found) {
47 return base::StringPrintf("Array must have at most %d items; found %d.",
48 maximum, found);
49 }
50
51 std::string TooFewStringChars(int minimum, int found) {
52 return base::StringPrintf(
53 "String must have at least %d characters; found %d.", minimum, found);
54 }
55
56 std::string TooManyStringChars(int maximum, int found) {
57 return base::StringPrintf("String must have at most %d characters; found %d.",
58 maximum, found);
59 }
60
61 std::string NumberTooSmall(int minimum) {
62 return base::StringPrintf("Value must be at least %d.", minimum);
63 }
64
65 std::string NumberTooLarge(int maximum) {
66 return base::StringPrintf("Value must be at most %d.", maximum);
67 }
68
69 std::string InvalidType(const char* expected_type, const char* actual_type) {
70 return base::StringPrintf("Invalid type: expected %s, found %s.",
71 expected_type, actual_type);
72 }
73
74 std::string NotAnInstance(const char* instance_type) {
75 return base::StringPrintf("Value must be an instance of %s.", instance_type);
76 }
77
78 std::string InvalidChoice() {
79 return "Value did not match any choice.";
80 }
81
82 std::string UnserializableValue() {
83 return "Value is unserializable.";
84 }
85
86 std::string ScriptThrewError() {
87 return "Script threw an error.";
88 }
89
90 std::string IndexError(uint32_t index, const std::string& error) {
91 return base::StringPrintf("Error at index %u: %s", index, error.c_str());
92 }
93
94 std::string PropertyError(const char* property_name, const std::string& error) {
95 return base::StringPrintf("Error at property '%s': %s", property_name,
96 error.c_str());
97 }
98
99 } // namespace api_errors
100 } // 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