Electroneum
Loading...
Searching...
No Matches
error.cpp
Go to the documentation of this file.
1// Copyright (c) 2014-2018, The Monero Project
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are
5// permitted provided that the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of
8// conditions and the following disclaimer.
9//
10// 2. Redistributions in binary form must reproduce the above copyright notice, this list
11// of conditions and the following disclaimer in the documentation and/or other
12// materials provided with the distribution.
13//
14// 3. Neither the name of the copyright holder nor the names of its contributors may be
15// used to endorse or promote products derived from this software without specific
16// prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
19// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "error.h"
29
30#include <lmdb.h>
31#include <string>
32
33namespace {
34 struct category final : std::error_category
35 {
36 virtual const char* name() const noexcept override final
37 {
38 return "lmdb::error_category()";
39 }
40
41 virtual std::string message(int value) const override final
42 {
43 char const* const msg = mdb_strerror(value);
44 if (msg)
45 return msg;
46 return "Unknown lmdb::error_category() value";
47 }
48
49 virtual std::error_condition default_error_condition(int value) const noexcept override final
50 {
51 switch (value)
52 {
53 case MDB_KEYEXIST:
54 case MDB_NOTFOUND:
55 break; // map to nothing generic
57 case MDB_CORRUPTED:
58 return std::errc::bad_address;
59 case MDB_PANIC:
61 case MDB_INVALID:
62 break; // map to nothing generic
63 case MDB_MAP_FULL:
64 return std::errc::no_buffer_space;
65 case MDB_DBS_FULL:
66 break; // map to nothing generic
68 case MDB_TLS_FULL:
69 return std::errc::no_lock_available;
70 case MDB_TXN_FULL:
71 case MDB_CURSOR_FULL:
72 case MDB_PAGE_FULL:
73 case MDB_MAP_RESIZED:
74 break; // map to nothing generic
76 return std::errc::invalid_argument;
77 case MDB_BAD_RSLOT:
78 case MDB_BAD_TXN:
79 case MDB_BAD_VALSIZE:
80 case MDB_BAD_DBI:
81 return std::errc::invalid_argument;
82 default:
83 return std::error_condition{value, std::generic_category()};
84 }
85 return std::error_condition{value, *this};
86 }
87 };
88}
89
90namespace lmdb
91{
92 std::error_category const& error_category() noexcept
93 {
94 static const category instance{};
95 return instance;
96 }
97}
98
std::string message("Message requiring signing")
#define MDB_PAGE_FULL
Definition lmdb.h:463
#define MDB_KEYEXIST
Definition lmdb.h:437
#define MDB_MAP_FULL
Definition lmdb.h:451
#define MDB_BAD_RSLOT
Definition lmdb.h:476
#define MDB_BAD_VALSIZE
Definition lmdb.h:480
#define MDB_DBS_FULL
Definition lmdb.h:453
#define MDB_MAP_RESIZED
Definition lmdb.h:465
#define MDB_PAGE_NOTFOUND
Definition lmdb.h:441
#define MDB_VERSION_MISMATCH
Definition lmdb.h:447
#define MDB_INVALID
Definition lmdb.h:449
#define MDB_INCOMPATIBLE
Definition lmdb.h:474
#define MDB_BAD_DBI
Definition lmdb.h:482
#define MDB_TLS_FULL
Definition lmdb.h:457
#define MDB_NOTFOUND
Definition lmdb.h:439
#define MDB_TXN_FULL
Definition lmdb.h:459
#define MDB_BAD_TXN
Definition lmdb.h:478
#define MDB_READERS_FULL
Definition lmdb.h:455
#define MDB_CURSOR_FULL
Definition lmdb.h:461
#define MDB_PANIC
Definition lmdb.h:445
#define MDB_CORRUPTED
Definition lmdb.h:443
char * mdb_strerror(int err)
Return a string describing a given error code.
Lightning memory-mapped database library.
const char * name
std::error_category const & error_category() noexcept
Definition error.cpp:92
const GenericPointer< typename T::ValueType > T2 value
Definition pointer.h:1225