1#ifndef SOURCEMETA_CORE_YAML_ERROR_H_
2#define SOURCEMETA_CORE_YAML_ERROR_H_
4#ifndef SOURCEMETA_CORE_YAML_EXPORT
5#include <sourcemeta/core/yaml_export.h>
15namespace sourcemeta::core {
21#pragma warning(disable : 4251 4275)
26class SOURCEMETA_CORE_YAML_EXPORT
YAMLError :
public std::exception {
29 YAMLError(
const char *message) : message_{message} {}
31 YAMLError(std::string &&message) =
delete;
32 YAMLError(std::string_view message) =
delete;
34 [[nodiscard]]
auto what() const noexcept -> const
char *
override {
35 return this->message_;
49 message_{
"Failed to parse the YAML document"} {}
54 : line_{
line}, column_{
column}, message_{message} {}
55 YAMLParseError(
const std::uint64_t line,
const std::uint64_t column,
56 std::string message) =
delete;
57 YAMLParseError(
const std::uint64_t line,
const std::uint64_t column,
58 std::string &&message) =
delete;
59 YAMLParseError(
const std::uint64_t line,
const std::uint64_t column,
60 std::string_view message) =
delete;
62 [[nodiscard]]
auto what() const noexcept -> const
char *
override {
63 return this->message_;
67 [[nodiscard]]
auto line() const noexcept -> std::uint64_t {
72 [[nodiscard]]
auto column() const noexcept -> std::uint64_t {
78 std::uint64_t column_;
88 const std::uint64_t
column,
const char *message)
91 const std::uint64_t column, std::string message) =
delete;
93 const std::uint64_t column,
94 std::string &&message) =
delete;
96 const std::uint64_t column,
97 std::string_view message) =
delete;
102 path_{std::move(
path)} {}
105 [[nodiscard]]
auto path() const noexcept -> const std::filesystem::
path & {
110 std::filesystem::path path_;
120 const std::uint64_t
line,
const std::uint64_t
column)
122 anchor_name_{anchor_name} {}
125 [[nodiscard]]
auto anchor() const noexcept -> std::string_view {
126 return this->anchor_name_;
130 std::string anchor_name_;
142 const std::uint64_t
line,
const std::uint64_t
column)
144 key_name_{key_name} {}
147 [[nodiscard]]
auto key() const noexcept -> std::string_view {
148 return this->key_name_;
152 std::string key_name_;
156#pragma warning(default : 4251 4275)
auto line() const noexcept -> std::uint64_t
Get the line number of the error.
Definition yaml_error.h:67
YAMLParseError(const std::uint64_t line, const std::uint64_t column)
Create a parsing error.
Definition yaml_error.h:47
YAMLFileParseError(std::filesystem::path path, const YAMLParseError &parent)
Create a file parsing error from a parse error.
Definition yaml_error.h:100
YAMLFileParseError(std::filesystem::path path, const std::uint64_t line, const std::uint64_t column, const char *message)
Create a file parsing error.
Definition yaml_error.h:87
YAMLError(const char *message)
Create a general error.
Definition yaml_error.h:29
YAMLUnknownAnchorError(const std::string_view anchor_name, const std::uint64_t line, const std::uint64_t column)
Create an unknown anchor error.
Definition yaml_error.h:119
YAMLDuplicateKeyError(const std::string_view key_name, const std::uint64_t line, const std::uint64_t column)
Create a duplicate key error.
Definition yaml_error.h:141
auto anchor() const noexcept -> std::string_view
Get the anchor name of the error.
Definition yaml_error.h:125
auto path() const noexcept -> const std::filesystem::path &
Get the file path of the error.
Definition yaml_error.h:105
YAMLParseError(const std::uint64_t line, const std::uint64_t column, const char *message)
Create a parsing error with a custom error.
Definition yaml_error.h:52
auto key() const noexcept -> std::string_view
Get the key name of the error.
Definition yaml_error.h:147
auto column() const noexcept -> std::uint64_t
Get the column number of the error.
Definition yaml_error.h:72