MySQL 9.4.0
Source Code Documentation
errors.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_JSON_MAPPER_VIEW_ERRORS_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_JSON_MAPPER_VIEW_ERRORS_H_
28
29#include <stdexcept>
30#include <string>
31
32namespace mrs {
33namespace database {
34
35class JSONInputError : public std::runtime_error {
36 public:
37 explicit JSONInputError(const std::string &msg)
38 : std::runtime_error("Invalid input JSON document: " + msg) {}
39};
40
41inline void throw_invalid_field(const std::string &table,
42 const std::string &field) {
43 throw JSONInputError("Invalid field \"" + field + "\" in table `" + table +
44 "` in JSON input");
45}
46
47inline void throw_missing_field(const std::string &table,
48 const std::string &field) {
49 throw JSONInputError("Field \"" + field + "\" for table `" + table +
50 "` missing in JSON input");
51}
52
53inline void throw_missing_id(const std::string &table) {
54 throw JSONInputError("ID for table `" + table + "` missing in JSON input");
55}
56
57inline void throw_mismatching_id(const std::string &table,
58 const std::string &column) {
59 throw JSONInputError("Value for column `" + column + "` of table `" + table +
60 "` does not match referenced ID");
61}
62
63inline void throw_immutable_id(const std::string &table) {
64 throw JSONInputError("ID for table `" + table + "` cannot be changed");
65}
66
67inline void throw_invalid_type(const std::string &table,
68 const std::string &field = "") {
69 if (field.empty())
70 throw JSONInputError("Invalid document in JSON input for table `" + table +
71 "`");
72 else
73 throw JSONInputError("Invalid value for \"" + field + "\" for table `" +
74 table + "` in JSON input");
75}
76
77inline void throw_duplicate_key(const std::string &table,
78 const std::string &field) {
79 throw JSONInputError("Duplicate keys in \"" + field + "\" for table `" +
80 table + "` in JSON input");
81}
82
83class DataMappingViewError : public std::runtime_error {
84 public:
85 explicit DataMappingViewError(const std::string &msg)
86 : std::runtime_error(msg) {}
87};
88
89inline void throw_ENOINSERT(const std::string &table) {
91 "Data Mapping View does not allow INSERT for table `" + table + "`");
92}
93
94inline void throw_ENOUPDATE(const std::string &table,
95 const std::string &field = "") {
96 if (field.empty())
98 "Data Mapping View does not allow UPDATE for table `" + table + "`");
99 else
101 "Data Mapping View does not allow UPDATE for field \"" + field +
102 "\" of table `" + table + "`");
103}
104
105inline void throw_ENODELETE(const std::string &table = "") {
106 if (table.empty())
108 "Data Mapping View does not allow DELETE for a referenced table");
109 else
111 "Data Mapping View does not allow DELETE for table `" + table + "`");
112}
113
114inline void throw_read_only() {
115 throw DataMappingViewError("Data Mapping View is read-only");
116}
117
118} // namespace database
119} // namespace mrs
120
121#endif // ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_JSON_MAPPER_VIEW_ERRORS_H_
DataMappingViewError(const std::string &msg)
Definition: errors.h:85
Definition: errors.h:35
JSONInputError(const std::string &msg)
Definition: errors.h:37
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
void throw_missing_id(const std::string &table)
Definition: errors.h:53
void throw_ENOUPDATE(const std::string &table, const std::string &field="")
Definition: errors.h:94
void throw_mismatching_id(const std::string &table, const std::string &column)
Definition: errors.h:57
void throw_ENODELETE(const std::string &table="")
Definition: errors.h:105
void throw_invalid_type(const std::string &table, const std::string &field="")
Definition: errors.h:67
void throw_duplicate_key(const std::string &table, const std::string &field)
Definition: errors.h:77
void throw_missing_field(const std::string &table, const std::string &field)
Definition: errors.h:47
void throw_read_only()
Definition: errors.h:114
void throw_ENOINSERT(const std::string &table)
Definition: errors.h:89
void throw_immutable_id(const std::string &table)
Definition: errors.h:63
void throw_invalid_field(const std::string &table, const std::string &field)
Definition: errors.h:41
Definition: authorize_manager.h:48
Definition: gcs_xcom_synode.h:64