MySQL 8.3.0
Source Code Documentation
json_error_handler.h
Go to the documentation of this file.
1#ifndef JSON_ERROR_HANDLER_INCLUDED
2#define JSON_ERROR_HANDLER_INCLUDED
3
4/* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is also distributed with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26#include <cstdlib>
27#include <functional>
28
29class THD;
30
32 std::function<void(const char *parse_err, size_t err_offset)>;
33using JsonErrorHandler = std::function<void()>;
34
35/**
36 Error handler for the functions that serialize a JSON value in the JSON binary
37 storage format. The member functions are called when an error occurs, and they
38 should report the error the way the caller has specified. When called from the
39 server, my_error() should be called to signal the error. The subclass
40 JsonSerializationDefaultErrorHandler, which calls my_error(), should be used
41 when called from server code.
42*/
44 public:
45 virtual ~JsonSerializationErrorHandler() = default;
46
47 /// Called when a JSON object contains a member with a name that is longer
48 /// than supported by the JSON binary format.
49 virtual void KeyTooBig() const = 0;
50
51 /// Called when a JSON document is too big to be stored in the JSON binary
52 /// format.
53 virtual void ValueTooBig() const = 0;
54
55 /// Called when a JSON document has more nesting levels than supported.
56 virtual void TooDeep() const = 0;
57
58 /// Called when an invalid JSON value is encountered.
59 virtual void InvalidJson() const = 0;
60
61 /// Called when an internal error occurs.
62 virtual void InternalError(const char *message) const = 0;
63
64 /// Check if the stack is about to be exhausted, and report the error.
65 /// @return true if the stack is about to be exhausted, false otherwise.
66 virtual bool CheckStack() const = 0;
67};
68
69#ifdef MYSQL_SERVER
70
72 public:
73 JsonParseDefaultErrorHandler(const char *func_name, int arg_idx)
74 : m_func_name(func_name), m_arg_idx(arg_idx) {}
75
76 void operator()(const char *parse_err, size_t err_offset) const;
77
78 private:
79 const char *m_func_name;
80 const int m_arg_idx;
81};
82
84
85/**
86 Error handler to be used when serializing JSON binary values in server code.
87 Uses my_error(), so it cannot be used in code outside of the server.
88*/
91 public:
92 explicit JsonSerializationDefaultErrorHandler(const THD *thd) : m_thd(thd) {}
93 void KeyTooBig() const override;
94 void ValueTooBig() const override;
95 void TooDeep() const override;
96 void InvalidJson() const override;
97 void InternalError(const char *message) const override;
98 bool CheckStack() const override;
99
100 private:
101 const THD *m_thd;
102};
103
104#endif // MYSQL_SERVER
105#endif // JSON_ERROR_HANDLER_INCLUDED
Definition: json_error_handler.h:71
const int m_arg_idx
Definition: json_error_handler.h:80
JsonParseDefaultErrorHandler(const char *func_name, int arg_idx)
Definition: json_error_handler.h:73
void operator()(const char *parse_err, size_t err_offset) const
Definition: json_error_handler.cc:31
const char * m_func_name
Definition: json_error_handler.h:79
Error handler to be used when serializing JSON binary values in server code.
Definition: json_error_handler.h:90
void TooDeep() const override
Called when a JSON document has more nesting levels than supported.
Definition: json_error_handler.cc:47
const THD * m_thd
Definition: json_error_handler.h:101
void KeyTooBig() const override
Called when a JSON object contains a member with a name that is longer than supported by the JSON bin...
Definition: json_error_handler.cc:39
void InternalError(const char *message) const override
Called when an internal error occurs.
Definition: json_error_handler.cc:55
void ValueTooBig() const override
Called when a JSON document is too big to be stored in the JSON binary format.
Definition: json_error_handler.cc:43
bool CheckStack() const override
Check if the stack is about to be exhausted, and report the error.
Definition: json_error_handler.cc:60
void InvalidJson() const override
Called when an invalid JSON value is encountered.
Definition: json_error_handler.cc:51
JsonSerializationDefaultErrorHandler(const THD *thd)
Definition: json_error_handler.h:92
Error handler for the functions that serialize a JSON value in the JSON binary storage format.
Definition: json_error_handler.h:43
virtual void InvalidJson() const =0
Called when an invalid JSON value is encountered.
virtual void ValueTooBig() const =0
Called when a JSON document is too big to be stored in the JSON binary format.
virtual bool CheckStack() const =0
Check if the stack is about to be exhausted, and report the error.
virtual void KeyTooBig() const =0
Called when a JSON object contains a member with a name that is longer than supported by the JSON bin...
virtual ~JsonSerializationErrorHandler()=default
virtual void InternalError(const char *message) const =0
Called when an internal error occurs.
virtual void TooDeep() const =0
Called when a JSON document has more nesting levels than supported.
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
void JsonDepthErrorHandler()
Definition: json_error_handler.cc:37
std::function< void()> JsonErrorHandler
Definition: json_error_handler.h:33
std::function< void(const char *parse_err, size_t err_offset)> JsonParseErrorHandler
Definition: json_error_handler.h:32