File: api_invocation_errors.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (131 lines) | stat: -rw-r--r-- 4,282 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/renderer/bindings/api_invocation_errors.h"

#include <string_view>
#include <vector>

#include "base/strings/string_util.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 kTypeAny[] = "any";

std::string InvalidEnumValue(const std::set<std::string>& valid_enums) {
  std::vector<std::string_view> options(valid_enums.begin(), valid_enums.end());
  std::string options_str = base::JoinString(options, ", ");
  return base::StringPrintf("Value must be one of %s.", options_str.c_str());
}

std::string MissingRequiredProperty(const char* property_name) {
  return base::StringPrintf("Missing required property '%s'.", property_name);
}

std::string UnexpectedProperty(const char* property_name) {
  return base::StringPrintf("Unexpected property: '%s'.", property_name);
}

std::string TooFewArrayItems(int minimum, int found) {
  return base::StringPrintf("Array must have at least %d items; found %d.",
                            minimum, found);
}

std::string TooManyArrayItems(int maximum, int found) {
  return base::StringPrintf("Array must have at most %d items; found %d.",
                            maximum, found);
}

std::string TooFewStringChars(int minimum, int found) {
  return base::StringPrintf(
      "String must have at least %d characters; found %d.", minimum, found);
}

std::string TooManyStringChars(int maximum, int found) {
  return base::StringPrintf("String must have at most %d characters; found %d.",
                            maximum, found);
}

std::string NumberTooSmall(int minimum) {
  return base::StringPrintf("Value must be at least %d.", minimum);
}

std::string NumberTooLarge(int maximum) {
  return base::StringPrintf("Value must be at most %d.", maximum);
}

std::string NumberIsNaNOrInfinity() {
  return base::StringPrintf("Value must not be NaN or Infinity.");
}

std::string InvalidType(const char* expected_type, const char* actual_type) {
  return base::StringPrintf("Invalid type: expected %s, found %s.",
                            expected_type, actual_type);
}

std::string NotAnInstance(const char* instance_type) {
  return base::StringPrintf("Value must be an instance of %s.", instance_type);
}

std::string InvalidChoice() {
  return "Value did not match any choice.";
}

std::string UnserializableValue() {
  return "Value is unserializable.";
}

std::string ScriptThrewError() {
  return "Script threw an error.";
}

std::string TooManyArguments() {
  return "Too many arguments.";
}

std::string NoMatchingSignature() {
  return "No matching signature.";
}

std::string MissingRequiredArgument(const char* argument_name) {
  return base::StringPrintf("Missing required argument '%s'.", argument_name);
}

std::string IndexError(uint32_t index, const std::string& error) {
  return base::StringPrintf("Error at index %u: %s", index, error.c_str());
}

std::string PropertyError(const char* property_name, const std::string& error) {
  return base::StringPrintf("Error at property '%s': %s", property_name,
                            error.c_str());
}

std::string ArgumentError(const std::string& parameter_name,
                          const std::string& error) {
  return base::StringPrintf("Error at parameter '%s': %s",
                            parameter_name.c_str(), error.c_str());
}

std::string InvocationError(const std::string& method_name,
                            const std::string& expected_signature,
                            const std::string& error) {
  return base::StringPrintf("Error in invocation of %s(%s): %s",
                            method_name.c_str(), expected_signature.c_str(),
                            error.c_str());
}

}  // namespace api_errors
}  // namespace extensions