blob: 2a902da8690aa9a2edf0611b85833e577a825b80 (
plain)
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
|
/*
* Copyright (c) 2022, Jan de Visser <jan@de-visser.net>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StringBuilder.h>
#include <LibSQL/Result.h>
namespace SQL {
DeprecatedString Result::error_string() const
{
VERIFY(is_error());
StringView error_code;
StringView error_description;
switch (m_error) {
#undef __ENUMERATE_SQL_ERROR
#define __ENUMERATE_SQL_ERROR(error, description) \
case SQLErrorCode::error: \
error_code = #error##sv; \
error_description = description##sv; \
break;
ENUMERATE_SQL_ERRORS(__ENUMERATE_SQL_ERROR)
#undef __ENUMERATE_SQL_ERROR
default:
VERIFY_NOT_REACHED();
}
StringBuilder builder;
builder.appendff("{}: ", error_code);
if (m_error_message.has_value()) {
if (error_description.find("{}"sv).has_value())
builder.appendff(error_description, *m_error_message);
else
builder.appendff("{}: {}", error_description, *m_error_message);
} else {
builder.append(error_description);
}
return builder.to_deprecated_string();
}
}
|