aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson_pull/exceptions.cpp
blob: e1d68493e79c82128279ad96ad448b3ca826ea1d (plain) (blame)
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
#include "exceptions.h"

#include <util/string/builder.h>

#include <cerrno>
#include <cstring>

using namespace NYsonPull::NException;

const char* TBadStream::what() const noexcept {
    TStringBuilder stream;
    stream << "Invalid YSON";
    if (Position_.Offset || Position_.Line || Position_.Column) {
        bool first = true;
        stream << " at ";
        if (Position_.Offset) {
            stream << "offset " << *Position_.Offset;
            first = false;
        }
        if (Position_.Line) {
            if (!first) {
                stream << ", ";
            }
            stream << "line " << *Position_.Line;
            first = false;
        }
        if (Position_.Column) {
            if (!first) {
                stream << ", ";
            }
            stream << "column " << *Position_.Column;
        }
    }
    stream << ": " << Message_;
    FormattedMessage_ = stream;
    return FormattedMessage_.c_str();
}

NYsonPull::NException::TSystemError::TSystemError()
    : SavedErrno_{errno} {
}

const char* NYsonPull::NException::TSystemError::what() const noexcept {
    return ::strerror(SavedErrno_);
}