Audacity 3.2.0
Error.cpp
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * SPDX-FileName: Error.cpp
4 * SPDX-FileContributor: Dmitry Vedenko
5 */
6#include "Error.h"
7
8#include <cassert>
9
10#include "AudacityException.h"
11#include "sqlite3.h"
12
13namespace audacity::sqlite
14{
15Error::Error() noexcept
16 : mCode(SQLITE_OK)
17{
18}
19
20Error::Error(int code) noexcept
21 : mCode(code)
22{
23}
24
25bool Error::IsError() const noexcept
26{
27 return mCode != SQLITE_OK && mCode != SQLITE_DONE && mCode != SQLITE_ROW;
28}
29
30bool Error::IsOk() const noexcept
31{
32 return !IsError();
33}
34
35Error::operator bool() const noexcept
36{
37 return IsOk();
38}
39
41{
42 assert(IsError());
43
46 Verbatim("(%d) %s").Format(GetCode(), GetErrorString()),
47 XO("SQLite3 error"));
48}
49
50int Error::GetCode() const noexcept
51{
52 return mCode;
53}
54
56{
57 switch (mCode)
58 {
59 case SQLITE_OK:
60 /* i18n-hint: database operation was successful */
61 return XO("No error");
62 case SQLITE_ERROR:
63 /* i18n-hint: database operation has failed, but there is no specific reason */
64 return XO("Generic error");
65 case SQLITE_INTERNAL:
66 /* i18n-hint: database operation has failed due to the internal error */
67 return XO("Internal logic error in SQLite");
68 case SQLITE_PERM:
69 /* i18n-hint: database operation has failed due to the permission error */
70 return XO("Access permission denied");
71 case SQLITE_ABORT:
72 /* i18n-hint: database operation was aborted by the callback */
73 return XO("Callback routine requested an abort");
74 case SQLITE_BUSY:
75 /* i18n-hint: database operation has failed because database is locked */
76 return XO("The database file is locked");
77 case SQLITE_LOCKED:
78 /* i18n-hint: database operation has failed because table is locked */
79 return XO("A table in the database is locked");
80 case SQLITE_NOMEM:
81 /* i18n-hint: database operation has failed due to the lack of memory */
82 return XO("A malloc() failed");
83 case SQLITE_READONLY:
84 /* i18n-hint: database operation has failed because database is read-only */
85 return XO("Attempt to write a read-only database");
86 case SQLITE_INTERRUPT:
87 /* i18n-hint: database operation was interrupted */
88 return XO("Operation terminated");
89 case SQLITE_IOERR:
90 /* i18n-hint: database operation has failed due to the I/O failure */
91 return XO("I/O error occurred");
92 case SQLITE_CORRUPT:
93 /* i18n-hint: database operation has failed due to the database corruption */
94 return XO("The database disk image is malformed");
95 case SQLITE_NOTFOUND:
96 /* i18n-hint: database operation has failed because the requested item was not found */
97 return XO("File not found");
98 case SQLITE_FULL:
99 /* i18n-hint: database operation has failed because the drive is full */
100 return XO("Insertion failed because the drive is full");
101 case SQLITE_CANTOPEN:
102 /* i18n-hint: database operation has failed because the file cannot be opened */
103 return XO("Unable to open the database file");
104 case SQLITE_PROTOCOL:
105 /* i18n-hint: database operation has failed because the lock protocol has failed */
106 return XO("Database lock protocol error");
107 case SQLITE_SCHEMA:
108 /* i18n-hint: database operation has failed because the database schema has changed */
109 return XO("The database schema changed");
110 case SQLITE_TOOBIG:
111 /* i18n-hint: database operation has failed because the string or BLOB exceeds size limit */
112 return XO("String or BLOB exceeds size limit");
113 case SQLITE_CONSTRAINT:
114 /* i18n-hint: database operation has failed due to the constraint violation */
115 return XO("Abort due to constraint violation");
116 case SQLITE_MISMATCH:
117 /* i18n-hint: database operation has failed due to the data type mismatch */
118 return XO("Data type mismatch");
119 case SQLITE_MISUSE:
120 /* i18n-hint: database operation has failed due to the library misuse */
121 return XO("Library used incorrectly");
122 case SQLITE_NOLFS:
123 /* i18n-hint: database operation has failed because the large file support is disabled */
124 return XO("The large file support is disabled");
125 case SQLITE_AUTH:
126 /* i18n-hint: database operation has failed due to the authorization error */
127 return XO("Authorization denied");
128 case SQLITE_FORMAT:
129 /* i18n-hint: database operation has failed due to the format error */
130 return XO("Not used");
131 case SQLITE_RANGE:
132 /* i18n-hint: database operation has failed because the parameter is out of range */
133 return XO("2nd parameter to sqlite3_bind out of range");
134 case SQLITE_NOTADB:
135 /* i18n-hint: database operation has failed because the file opened is not a database file */
136 return XO("File opened that is not a database file ");
137 default:
138 /* i18n-hint: database operation has failed due to the unknown error */
139 return XO("Unknown error");
140 }
141}
142} // namespace audacity::sqlite
Declare abstract class AudacityException, some often-used subclasses, and GuardedCall.
@ Internal
Indicates internal failure from Audacity.
XO("Cut/Copy/Paste")
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
Abstract base class used in importing a file.
A MessageBoxException that shows a given, unvarying string.
Holds a msgid for the translation catalog; may also bind format arguments.
bool IsError() const noexcept
Returns true if the object represents an error.
Definition: Error.cpp:25
Error() noexcept
Definition: Error.cpp:15
TranslatableString GetErrorString() const
Definition: Error.cpp:55
int GetCode() const noexcept
Definition: Error.cpp:50
bool IsOk() const noexcept
Returns true if the object represents a success code.
Definition: Error.cpp:30
void Raise() const
Definition: Error.cpp:40