Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
json_error.h
1#ifndef SOURCEMETA_CORE_JSON_ERROR_H_
2#define SOURCEMETA_CORE_JSON_ERROR_H_
3
4#ifndef SOURCEMETA_CORE_JSON_EXPORT
5#include <sourcemeta/core/json_export.h>
6#endif
7
8#include <sourcemeta/core/error.h>
9
10#include <cstdint> // std::uint64_t
11#include <filesystem> // std::filesystem::path
12#include <utility> // std::move
13
14namespace sourcemeta::core {
15
16SOURCEMETA_CORE_ERROR_WARNINGS_PUSH
17
20class SOURCEMETA_CORE_JSON_EXPORT JSONParseError : public Error {
21public:
23 JSONParseError(const std::uint64_t line, const std::uint64_t column) noexcept
24 : Error{"Failed to parse the JSON document"}, line_{line},
25 column_{column} {}
26
28 JSONParseError(const StaticString message, const std::uint64_t line,
29 const std::uint64_t column) noexcept
30 : Error{message}, line_{line}, column_{column} {}
31
33 [[nodiscard]] auto line() const noexcept -> std::uint64_t {
34 return this->line_;
35 }
36
38 [[nodiscard]] auto column() const noexcept -> std::uint64_t {
39 return this->column_;
40 }
41
42private:
43 std::uint64_t line_;
44 std::uint64_t column_;
45};
46
49class SOURCEMETA_CORE_JSON_EXPORT JSONFileParseError : public JSONParseError {
50public:
52 JSONFileParseError(const StaticString message, std::filesystem::path path,
53 const std::uint64_t line, const std::uint64_t column)
54 : JSONParseError{message, line, column}, path_{std::move(path)} {}
55
57 JSONFileParseError(std::filesystem::path path, const JSONParseError &parent)
58 : JSONParseError{parent.message(), parent.line(), parent.column()},
59 path_{std::move(path)} {}
60
62 [[nodiscard]] auto path() const noexcept -> const std::filesystem::path & {
63 return this->path_;
64 }
65
66private:
67 std::filesystem::path path_;
68};
69
73class SOURCEMETA_CORE_JSON_EXPORT JSONNonFiniteError : public Error {
74public:
75 JSONNonFiniteError() noexcept
76 : Error{"JSON does not support Infinity or NaN"} {}
77};
78
82class SOURCEMETA_CORE_JSON_EXPORT JSONIntegerRangeError : public Error {
83public:
86};
87
88SOURCEMETA_CORE_ERROR_WARNINGS_POP
89
90} // namespace sourcemeta::core
91
92#endif
auto message() const noexcept -> StaticString
Definition error_base.h:78
Error(const StaticString message) noexcept
Construct the error given its message.
Definition error_base.h:84
auto column() const noexcept -> std::uint64_t
Get the column number of the error.
Definition json_error.h:38
JSONIntegerRangeError(const StaticString message) noexcept
Construct an error with the given message.
Definition json_error.h:85
auto line() const noexcept -> std::uint64_t
Get the line number of the error.
Definition json_error.h:33
JSONFileParseError(const StaticString message, std::filesystem::path path, const std::uint64_t line, const std::uint64_t column)
Create a file parsing error.
Definition json_error.h:52
auto path() const noexcept -> const std::filesystem::path &
Get the file path of the error.
Definition json_error.h:62
JSONParseError(const std::uint64_t line, const std::uint64_t column) noexcept
Create a parsing error.
Definition json_error.h:23
JSONParseError(const StaticString message, const std::uint64_t line, const std::uint64_t column) noexcept
Create a parsing error with a custom message.
Definition json_error.h:28
JSONFileParseError(std::filesystem::path path, const JSONParseError &parent)
Create a file parsing error from a parse error.
Definition json_error.h:57
Definition text_static_string.h:20