File: Error.cpp

package info (click to toggle)
audacity 3.7.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 134,800 kB
  • sloc: cpp: 366,277; ansic: 198,323; lisp: 7,761; sh: 3,414; python: 1,501; xml: 1,385; perl: 854; makefile: 125
file content (142 lines) | stat: -rw-r--r-- 5,091 bytes parent folder | download | duplicates (2)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * SPDX-License-Identifier: GPL-2.0-or-later
 * SPDX-FileName: Error.cpp
 * SPDX-FileContributor: Dmitry Vedenko
 */
#include "Error.h"

#include <cassert>

#include "AudacityException.h"
#include "sqlite3.h"

namespace audacity::sqlite
{
Error::Error() noexcept
    : mCode(SQLITE_OK)
{
}

Error::Error(int code) noexcept
    : mCode(code)
{
}

bool Error::IsError() const noexcept
{
   return mCode != SQLITE_OK && mCode != SQLITE_DONE && mCode != SQLITE_ROW;
}

bool Error::IsOk() const noexcept
{
   return !IsError();
}

Error::operator bool() const noexcept
{
   return IsOk();
}

void sqlite::Error::Raise() const
{
   assert(IsError());

   throw SimpleMessageBoxException(
      ExceptionType::Internal,
      Verbatim("(%d) %s").Format(GetCode(), GetErrorString()),
      XO("SQLite3 error"));
}

int Error::GetCode() const noexcept
{
   return mCode;
}

TranslatableString Error::GetErrorString() const
{
   switch (mCode)
   {
   case SQLITE_OK:
      /* i18n-hint: database operation was successful */
      return XO("No error");
   case SQLITE_ERROR:
      /* i18n-hint: database operation has failed, but there is no specific reason */
      return XO("Generic error");
   case SQLITE_INTERNAL:
      /* i18n-hint: database operation has failed due to the internal error */
      return XO("Internal logic error in SQLite");
   case SQLITE_PERM:
      /* i18n-hint: database operation has failed due to the permission error */
      return XO("Access permission denied");
   case SQLITE_ABORT:
      /* i18n-hint: database operation was aborted by the callback */
      return XO("Callback routine requested an abort");
   case SQLITE_BUSY:
      /* i18n-hint: database operation has failed because database is locked */
      return XO("The database file is locked");
   case SQLITE_LOCKED:
      /* i18n-hint: database operation has failed because table is locked */
      return XO("A table in the database is locked");
   case SQLITE_NOMEM:
      /* i18n-hint: database operation has failed due to the lack of memory */
      return XO("A malloc() failed");
   case SQLITE_READONLY:
      /* i18n-hint: database operation has failed because database is read-only */
      return XO("Attempt to write a read-only database");
   case SQLITE_INTERRUPT:
      /* i18n-hint: database operation was interrupted */
      return XO("Operation terminated");
   case SQLITE_IOERR:
      /* i18n-hint: database operation has failed due to the I/O failure */
      return XO("I/O error occurred");
   case SQLITE_CORRUPT:
      /* i18n-hint: database operation has failed due to the database corruption */
      return XO("The database disk image is malformed");
   case SQLITE_NOTFOUND:
      /* i18n-hint: database operation has failed because the requested item was not found */
      return XO("File not found");
   case SQLITE_FULL:
      /* i18n-hint: database operation has failed because the drive is full */
      return XO("Insertion failed because the drive is full");
   case SQLITE_CANTOPEN:
      /* i18n-hint: database operation has failed because the file cannot be opened */
      return XO("Unable to open the database file");
   case SQLITE_PROTOCOL:
      /* i18n-hint: database operation has failed because the lock protocol has failed */
      return XO("Database lock protocol error");
   case SQLITE_SCHEMA:
      /* i18n-hint: database operation has failed because the database schema has changed */
      return XO("The database schema changed");
   case SQLITE_TOOBIG:
      /* i18n-hint: database operation has failed because the string or BLOB exceeds size limit */
      return XO("String or BLOB exceeds size limit");
   case SQLITE_CONSTRAINT:
      /* i18n-hint: database operation has failed due to the constraint violation */
      return XO("Abort due to constraint violation");
   case SQLITE_MISMATCH:
      /* i18n-hint: database operation has failed due to the data type mismatch */
      return XO("Data type mismatch");
   case SQLITE_MISUSE:
      /* i18n-hint: database operation has failed due to the library misuse */
      return XO("Library used incorrectly");
   case SQLITE_NOLFS:
      /* i18n-hint: database operation has failed because the large file support is disabled */
      return XO("The large file support is disabled");
   case SQLITE_AUTH:
      /* i18n-hint: database operation has failed due to the authorization error */
      return XO("Authorization denied");
   case SQLITE_FORMAT:
      /* i18n-hint: database operation has failed due to the format error */
      return XO("Not used");
   case SQLITE_RANGE:
      /* i18n-hint: database operation has failed because the parameter is out of range */
      return XO("2nd parameter to sqlite3_bind out of range");
   case SQLITE_NOTADB:
      /* i18n-hint: database operation has failed because the file opened is not a database file */
      return XO("File opened that is not a database file ");
   default:
      /* i18n-hint: database operation has failed due to the unknown error */
      return XO("Unknown error");
   }
}
} // namespace audacity::sqlite