aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/microbdb/header.cpp
blob: f4511d6fb624393e5c6a8d633e23c95e4c76f033 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "header.h"

#include <util/stream/output.h>
#include <util/stream/format.h>

TString ToString(EMbdbErrors error) {
    TString ret;
    switch (error) {
        case MBDB_ALREADY_INITIALIZED:
            ret = "already initialized";
            break;
        case MBDB_NOT_INITIALIZED:
            ret = "not initialized";
            break;
        case MBDB_BAD_DESCRIPTOR:
            ret = "bad descriptor";
            break;
        case MBDB_OPEN_ERROR:
            ret = "open error";
            break;
        case MBDB_READ_ERROR:
            ret = "read error";
            break;
        case MBDB_WRITE_ERROR:
            ret = "write error";
            break;
        case MBDB_CLOSE_ERROR:
            ret = "close error";
            break;
        case MBDB_EXPECTED_EOF:
            ret = "expected eof";
            break;
        case MBDB_UNEXPECTED_EOF:
            ret = "unxepected eof";
            break;
        case MBDB_BAD_FILENAME:
            ret = "bad filename";
            break;
        case MBDB_BAD_METAPAGE:
            ret = "bad metapage";
            break;
        case MBDB_BAD_RECORDSIG:
            ret = "bad recordsig";
            break;
        case MBDB_BAD_FILE_SIZE:
            ret = "bad file size";
            break;
        case MBDB_BAD_PAGESIG:
            ret = "bad pagesig";
            break;
        case MBDB_BAD_PAGESIZE:
            ret = "bad pagesize";
            break;
        case MBDB_BAD_PARM:
            ret = "bad parm";
            break;
        case MBDB_BAD_SYNC:
            ret = "bad sync";
            break;
        case MBDB_PAGE_OVERFLOW:
            ret = "page overflow";
            break;
        case MBDB_NO_MEMORY:
            ret = "no memory";
            break;
        case MBDB_MEMORY_LEAK:
            ret = "memory leak";
            break;
        case MBDB_NOT_SUPPORTED:
            ret = "not supported";
            break;
        default:
            ret = "unknown";
            break;
    }
    return ret;
}

TString ErrorMessage(int error, const TString& text, const TString& path, ui32 recordSig, ui32 gotRecordSig) {
    TStringStream str;
    str << text;
    if (path.size())
        str << " '" << path << "'";
    str << ": " << ToString(static_cast<EMbdbErrors>(error));
    if (recordSig && (!gotRecordSig || recordSig != gotRecordSig))
        str << ". Expected RecordSig: " << Hex(recordSig, HF_ADDX);
    if (recordSig && gotRecordSig && recordSig != gotRecordSig)
        str << ", got: " << Hex(gotRecordSig, HF_ADDX);
    str << ". Last system error text: " << LastSystemErrorText();
    return str.Str();
}