|
a |
|
b/qiita_db/exceptions.py |
|
|
1 |
# ----------------------------------------------------------------------------- |
|
|
2 |
# Copyright (c) 2014--, The Qiita Development Team. |
|
|
3 |
# |
|
|
4 |
# Distributed under the terms of the BSD 3-clause License. |
|
|
5 |
# |
|
|
6 |
# The full license is in the file LICENSE, distributed with this software. |
|
|
7 |
# ----------------------------------------------------------------------------- |
|
|
8 |
import warnings |
|
|
9 |
|
|
|
10 |
from qiita_core.exceptions import QiitaError |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
class QiitaDBError(QiitaError): |
|
|
14 |
"""Base class for all qiita_db exceptions""" |
|
|
15 |
pass |
|
|
16 |
|
|
|
17 |
|
|
|
18 |
class QiitaDBNotImplementedError(QiitaDBError): |
|
|
19 |
"""""" |
|
|
20 |
pass |
|
|
21 |
|
|
|
22 |
|
|
|
23 |
class QiitaDBExecutionError(QiitaDBError): |
|
|
24 |
"""Exception for error when executing SQL queries""" |
|
|
25 |
pass |
|
|
26 |
|
|
|
27 |
|
|
|
28 |
class QiitaDBConnectionError(QiitaDBError): |
|
|
29 |
"""Exception for error when connecting to the db""" |
|
|
30 |
pass |
|
|
31 |
|
|
|
32 |
|
|
|
33 |
class QiitaDBColumnError(QiitaDBError): |
|
|
34 |
"""Exception when missing table information or excess information passed""" |
|
|
35 |
pass |
|
|
36 |
|
|
|
37 |
|
|
|
38 |
class QiitaDBLookupError(QiitaDBError, LookupError): |
|
|
39 |
"""Exception when converting or getting non-existant values in DB""" |
|
|
40 |
pass |
|
|
41 |
|
|
|
42 |
|
|
|
43 |
class QiitaDBOperationNotPermittedError(QiitaDBError): |
|
|
44 |
"""Exception when perofrming an operation not permitted""" |
|
|
45 |
pass |
|
|
46 |
|
|
|
47 |
|
|
|
48 |
class QiitaDBArtifactCreationError(QiitaDBError): |
|
|
49 |
"""Exception when creating an artifact""" |
|
|
50 |
def __init__(self, reason): |
|
|
51 |
super(QiitaDBArtifactCreationError, self).__init__() |
|
|
52 |
self.args = (f"Cannot create artifact: {reason}",) |
|
|
53 |
|
|
|
54 |
|
|
|
55 |
class QiitaDBArtifactDeletionError(QiitaDBError): |
|
|
56 |
"""Exception when deleting an artifact""" |
|
|
57 |
def __init__(self, a_id, reason): |
|
|
58 |
super(QiitaDBArtifactDeletionError, self).__init__() |
|
|
59 |
self.args = (f"Cannot delete artifact {a_id}: {reason}",) |
|
|
60 |
|
|
|
61 |
|
|
|
62 |
class QiitaDBDuplicateError(QiitaDBError): |
|
|
63 |
"""Exception when duplicating something in the database""" |
|
|
64 |
def __init__(self, obj_name, attributes): |
|
|
65 |
super(QiitaDBDuplicateError, self).__init__() |
|
|
66 |
self.args = ("The '%s' object with attributes (%s) already exists." |
|
|
67 |
% (obj_name, attributes),) |
|
|
68 |
|
|
|
69 |
|
|
|
70 |
class QiitaDBStatusError(QiitaDBError): |
|
|
71 |
"""Exception when editing is done with an unallowed status""" |
|
|
72 |
pass |
|
|
73 |
|
|
|
74 |
|
|
|
75 |
class QiitaDBUnknownIDError(QiitaDBError): |
|
|
76 |
"""Exception for error when an object does not exists in the DB""" |
|
|
77 |
def __init__(self, missing_id, table): |
|
|
78 |
super(QiitaDBUnknownIDError, self).__init__() |
|
|
79 |
self.args = ("The object with ID '%s' does not exists in table '%s'" |
|
|
80 |
% (missing_id, table),) |
|
|
81 |
|
|
|
82 |
|
|
|
83 |
class QiitaDBDuplicateHeaderError(QiitaDBError): |
|
|
84 |
"""Exception for error when a MetadataTemplate has duplicate columns""" |
|
|
85 |
def __init__(self, repeated_headers): |
|
|
86 |
super(QiitaDBDuplicateHeaderError, self).__init__() |
|
|
87 |
self.args = ("Duplicate headers found in MetadataTemplate. Note " |
|
|
88 |
"that the headers are not case-sensitive, repeated " |
|
|
89 |
"header(s): %s." % ', '.join(repeated_headers),) |
|
|
90 |
|
|
|
91 |
|
|
|
92 |
class QiitaDBDuplicateSamplesError(QiitaDBError): |
|
|
93 |
"""Exception for error when a MetadataTemplate has duplicate columns""" |
|
|
94 |
def __init__(self, repeated_samples): |
|
|
95 |
super(QiitaDBDuplicateSamplesError, self).__init__() |
|
|
96 |
self.args = ("Duplicate samples found in MetadataTemplate: %s." |
|
|
97 |
% ', '.join(repeated_samples),) |
|
|
98 |
|
|
|
99 |
|
|
|
100 |
class QiitaDBIncompatibleDatatypeError(QiitaDBError): |
|
|
101 |
"""When arguments are used with incompatible operators in a query""" |
|
|
102 |
def __init__(self, operator, argument_type): |
|
|
103 |
super(QiitaDBIncompatibleDatatypeError, self).__init__() |
|
|
104 |
self.args = ("The %s operator is not for use with data of type %s" % |
|
|
105 |
(operator, str(argument_type))) |
|
|
106 |
|
|
|
107 |
|
|
|
108 |
class QiitaDBWarning(UserWarning): |
|
|
109 |
"""Warning specific for the QiitaDB domain""" |
|
|
110 |
pass |
|
|
111 |
|
|
|
112 |
|
|
|
113 |
warnings.simplefilter('always', QiitaDBWarning) |