baserow.error
This module contains the custom exceptions of the package.
1""" 2This module contains the custom exceptions of the package. 3""" 4 5 6class PackageClientNotConfiguredError(Exception): 7 """ 8 Thrown when the PackageClient is intended to be used but has not been 9 configured yet. 10 """ 11 12 def __str__(self) -> str: 13 return "the package-wide GlobalClient is not defined; it must first be configured with configure()" 14 15 16class PackageClientAlreadyConfiguredError(Exception): 17 """ 18 This exception is thrown if the package user attempts to call the 19 baserow.config_client() method multiple times. To prevent unpredictable 20 behavior, the package-wide client can only be set once per runtime. 21 22 Args: 23 old_url (str): The URL that has already been set for the package-wide 24 client. 25 new_url (str): The URL that the user is attempting to set anew. 26 """ 27 28 def __init__(self, old_url: str, new_url: str): 29 self.old_url = old_url 30 self.new_url = new_url 31 32 def __str__(self) -> str: 33 return f"attempted to configure the package-wide client with the URL '{self.new_url}', even though it was already configured with the URL '{self.old_url}'" 34 35 36class NoClientAvailableError(Exception): 37 """ 38 Thrown when a Table instance is not given a client, and the GlobalClient of 39 the package is not configured. This would implicitly raise a 40 PackageClientNotConfiguredError, but this behavior is not transparent to the 41 package user and could be confusing. Therefore, this exception was created 42 for this case (when using the ORM-like abstraction). 43 44 Args: 45 table_name (str): Name of the table. 46 """ 47 48 def __init__(self, table_name: str): 49 self.table_name = table_name 50 51 def __str__(self) -> str: 52 return f"there is no API client available for the table '{self.table_name}'. Either configure the package-wide GlobalClient or use the client property of your Table model" 53 54 55class JWTAuthRequiredError(Exception): 56 """ 57 Thrown when an operation with the API is only possible with user credentials 58 authentication. 59 60 Args: 61 name (str): Name or short description of the operation. 62 """ 63 64 def __init__(self, name: str): 65 self.name = name 66 67 def __str__(self) -> str: 68 return f"the {self.name} method only works with a JWT (username and password) authentication" 69 70 71class BaserowError(Exception): 72 """ 73 Exception thrown when an HTTP request to the Baserow REST API returns an 74 error. 75 76 Args: 77 status_code (int): HTTP status code. 78 name (str): Name/title of the error. 79 detail (str): Additional detail. 80 """ 81 82 def __init__(self, status_code: int, name: str, detail: str): 83 self.status_code = status_code 84 self.name = name 85 self.detail = detail 86 87 def __str__(self) -> str: 88 return f"Baserow returned an {self.name} error with status code {self.status_code}: {self.detail}" 89 90 91class UnspecifiedBaserowError(Exception): 92 """ 93 Thrown when the Baserow HTTP call returns a non-success state but not with 94 status code 400. 95 96 Args: 97 status_code (int): HTTP status code. 98 body (str): String representation of the body. 99 """ 100 101 def __init__(self, status_code: int, body: str): 102 self.status_code = status_code 103 self.body = body 104 105 def __str__(self) -> str: 106 return f"Baserow returned an error with status code {self.status_code}: {self.body}" 107 108 109class InvalidTableConfigurationError(Exception): 110 """ 111 Raised when a Table model is not implemented correctly. 112 113 Args: 114 model_name (str): Name of the model. 115 reason (str): Reason for the exception. 116 """ 117 118 def __init__(self, model_name: str, reason: str): 119 self.model_name = model_name 120 self.reason = reason 121 122 def __str__(self) -> str: 123 return f"the configuration of the '{self.model_name}' table model is incorrect, {self.reason}" 124 125 126class RowIDNotSetError(Exception): 127 """ 128 Raised when a method of a `Table` instance requires the `Table.row_id` 129 but it has not been set. 130 """ 131 132 def __init__(self, model_name: str, method_name: str): 133 self.model_name = model_name 134 self.method_name = method_name 135 136 def __str__(self) -> str: 137 return f"{self.method_name} only works on a {self.model_name} table if the row_id is set" 138 139 140class PydanticGenericMetadataError(Exception): 141 """ 142 Thrown when the type of the generic type of a generic model could not be 143 determined. 144 145 Args: 146 model_name (str): Name of the model. 147 generic_name (str): Name/usage of the generic. 148 reason (str): Reason for the failure. 149 """ 150 @classmethod 151 def args_missing(cls, model_name: str, generic_name: str): 152 """The exception if there is no args field in the metadata.""" 153 return cls(model_name, generic_name, "args not in __pydantic_generic_metadata__") 154 155 @classmethod 156 def args_empty(cls, model_name: str, generic_name: str): 157 """ 158 The exception if the tuple of the args field in the metadata is empty. 159 """ 160 return cls(model_name, generic_name, "args tuple in __pydantic_generic_metadata__ is empty") 161 162 def __init__(self, model_name: str, generic_name: str, reason: str): 163 self.model_name = model_name 164 self.generic_name = generic_name 165 self.reason = reason 166 167 def __str__(self) -> str: 168 return f"couldn't determine {self.generic_name} of {self.model_name}, {self.reason}" 169 170 171class InvalidFieldForCreateTableError(Exception): 172 """ 173 This error is raised when a field in a `Table` model is not suitable for 174 automatically creating a new table in Baserow. 175 176 Args: 177 field_name (str): Name of the erroneous field. 178 reason (str): Reason for the failure. 179 """ 180 181 def __init__(self, field_name: str, reason: str): 182 self.field_name = field_name 183 self.reason = reason 184 185 def __str__(self) -> str: 186 return f"it was not possible to create a field in Baserow for the model field {self.field_name}, {self.reason}" 187 188 189class NoPrimaryFieldError(Exception): 190 """ 191 Thrown when a table model has not defined a primary field. See the 192 documentation of table.Table.primary_field() for more information on 193 declaring a primary field. 194 195 Args: 196 model_name (str): Name of the model. 197 """ 198 199 def __init__(self, model_name: str): 200 self.model_name = model_name 201 202 def __str__(self) -> str: 203 return f"the model {self.model_name} does not define a primary field" 204 205 206class MultiplePrimaryFieldsError(Exception): 207 """ 208 Thrown when a table model has more than one primary field defined. Only one 209 is allowed. See the documentation of `table.Table.primary_field()` for more 210 information on declaring a primary field. 211 212 Args: 213 model_name (str): Name of the model. 214 """ 215 216 def __init__(self, model_name: str): 217 self.model_name = model_name 218 219 def __str__(self) -> str: 220 return f"the model {self.model_name} defines more than one primary field, only one is allowed"
7class PackageClientNotConfiguredError(Exception): 8 """ 9 Thrown when the PackageClient is intended to be used but has not been 10 configured yet. 11 """ 12 13 def __str__(self) -> str: 14 return "the package-wide GlobalClient is not defined; it must first be configured with configure()"
Thrown when the PackageClient is intended to be used but has not been configured yet.
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
17class PackageClientAlreadyConfiguredError(Exception): 18 """ 19 This exception is thrown if the package user attempts to call the 20 baserow.config_client() method multiple times. To prevent unpredictable 21 behavior, the package-wide client can only be set once per runtime. 22 23 Args: 24 old_url (str): The URL that has already been set for the package-wide 25 client. 26 new_url (str): The URL that the user is attempting to set anew. 27 """ 28 29 def __init__(self, old_url: str, new_url: str): 30 self.old_url = old_url 31 self.new_url = new_url 32 33 def __str__(self) -> str: 34 return f"attempted to configure the package-wide client with the URL '{self.new_url}', even though it was already configured with the URL '{self.old_url}'"
This exception is thrown if the package user attempts to call the baserow.config_client() method multiple times. To prevent unpredictable behavior, the package-wide client can only be set once per runtime.
Arguments:
- old_url (str): The URL that has already been set for the package-wide client.
- new_url (str): The URL that the user is attempting to set anew.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
37class NoClientAvailableError(Exception): 38 """ 39 Thrown when a Table instance is not given a client, and the GlobalClient of 40 the package is not configured. This would implicitly raise a 41 PackageClientNotConfiguredError, but this behavior is not transparent to the 42 package user and could be confusing. Therefore, this exception was created 43 for this case (when using the ORM-like abstraction). 44 45 Args: 46 table_name (str): Name of the table. 47 """ 48 49 def __init__(self, table_name: str): 50 self.table_name = table_name 51 52 def __str__(self) -> str: 53 return f"there is no API client available for the table '{self.table_name}'. Either configure the package-wide GlobalClient or use the client property of your Table model"
Thrown when a Table instance is not given a client, and the GlobalClient of the package is not configured. This would implicitly raise a PackageClientNotConfiguredError, but this behavior is not transparent to the package user and could be confusing. Therefore, this exception was created for this case (when using the ORM-like abstraction).
Arguments:
- table_name (str): Name of the table.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
56class JWTAuthRequiredError(Exception): 57 """ 58 Thrown when an operation with the API is only possible with user credentials 59 authentication. 60 61 Args: 62 name (str): Name or short description of the operation. 63 """ 64 65 def __init__(self, name: str): 66 self.name = name 67 68 def __str__(self) -> str: 69 return f"the {self.name} method only works with a JWT (username and password) authentication"
Thrown when an operation with the API is only possible with user credentials authentication.
Arguments:
- name (str): Name or short description of the operation.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
72class BaserowError(Exception): 73 """ 74 Exception thrown when an HTTP request to the Baserow REST API returns an 75 error. 76 77 Args: 78 status_code (int): HTTP status code. 79 name (str): Name/title of the error. 80 detail (str): Additional detail. 81 """ 82 83 def __init__(self, status_code: int, name: str, detail: str): 84 self.status_code = status_code 85 self.name = name 86 self.detail = detail 87 88 def __str__(self) -> str: 89 return f"Baserow returned an {self.name} error with status code {self.status_code}: {self.detail}"
Exception thrown when an HTTP request to the Baserow REST API returns an error.
Arguments:
- status_code (int): HTTP status code.
- name (str): Name/title of the error.
- detail (str): Additional detail.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
92class UnspecifiedBaserowError(Exception): 93 """ 94 Thrown when the Baserow HTTP call returns a non-success state but not with 95 status code 400. 96 97 Args: 98 status_code (int): HTTP status code. 99 body (str): String representation of the body. 100 """ 101 102 def __init__(self, status_code: int, body: str): 103 self.status_code = status_code 104 self.body = body 105 106 def __str__(self) -> str: 107 return f"Baserow returned an error with status code {self.status_code}: {self.body}"
Thrown when the Baserow HTTP call returns a non-success state but not with status code 400.
Arguments:
- status_code (int): HTTP status code.
- body (str): String representation of the body.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
110class InvalidTableConfigurationError(Exception): 111 """ 112 Raised when a Table model is not implemented correctly. 113 114 Args: 115 model_name (str): Name of the model. 116 reason (str): Reason for the exception. 117 """ 118 119 def __init__(self, model_name: str, reason: str): 120 self.model_name = model_name 121 self.reason = reason 122 123 def __str__(self) -> str: 124 return f"the configuration of the '{self.model_name}' table model is incorrect, {self.reason}"
Raised when a Table model is not implemented correctly.
Arguments:
- model_name (str): Name of the model.
- reason (str): Reason for the exception.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
127class RowIDNotSetError(Exception): 128 """ 129 Raised when a method of a `Table` instance requires the `Table.row_id` 130 but it has not been set. 131 """ 132 133 def __init__(self, model_name: str, method_name: str): 134 self.model_name = model_name 135 self.method_name = method_name 136 137 def __str__(self) -> str: 138 return f"{self.method_name} only works on a {self.model_name} table if the row_id is set"
Raised when a method of a Table
instance requires the Table.row_id
but it has not been set.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
141class PydanticGenericMetadataError(Exception): 142 """ 143 Thrown when the type of the generic type of a generic model could not be 144 determined. 145 146 Args: 147 model_name (str): Name of the model. 148 generic_name (str): Name/usage of the generic. 149 reason (str): Reason for the failure. 150 """ 151 @classmethod 152 def args_missing(cls, model_name: str, generic_name: str): 153 """The exception if there is no args field in the metadata.""" 154 return cls(model_name, generic_name, "args not in __pydantic_generic_metadata__") 155 156 @classmethod 157 def args_empty(cls, model_name: str, generic_name: str): 158 """ 159 The exception if the tuple of the args field in the metadata is empty. 160 """ 161 return cls(model_name, generic_name, "args tuple in __pydantic_generic_metadata__ is empty") 162 163 def __init__(self, model_name: str, generic_name: str, reason: str): 164 self.model_name = model_name 165 self.generic_name = generic_name 166 self.reason = reason 167 168 def __str__(self) -> str: 169 return f"couldn't determine {self.generic_name} of {self.model_name}, {self.reason}"
Thrown when the type of the generic type of a generic model could not be determined.
Arguments:
- model_name (str): Name of the model.
- generic_name (str): Name/usage of the generic.
- reason (str): Reason for the failure.
151 @classmethod 152 def args_missing(cls, model_name: str, generic_name: str): 153 """The exception if there is no args field in the metadata.""" 154 return cls(model_name, generic_name, "args not in __pydantic_generic_metadata__")
The exception if there is no args field in the metadata.
156 @classmethod 157 def args_empty(cls, model_name: str, generic_name: str): 158 """ 159 The exception if the tuple of the args field in the metadata is empty. 160 """ 161 return cls(model_name, generic_name, "args tuple in __pydantic_generic_metadata__ is empty")
The exception if the tuple of the args field in the metadata is empty.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
172class InvalidFieldForCreateTableError(Exception): 173 """ 174 This error is raised when a field in a `Table` model is not suitable for 175 automatically creating a new table in Baserow. 176 177 Args: 178 field_name (str): Name of the erroneous field. 179 reason (str): Reason for the failure. 180 """ 181 182 def __init__(self, field_name: str, reason: str): 183 self.field_name = field_name 184 self.reason = reason 185 186 def __str__(self) -> str: 187 return f"it was not possible to create a field in Baserow for the model field {self.field_name}, {self.reason}"
This error is raised when a field in a Table
model is not suitable for
automatically creating a new table in Baserow.
Arguments:
- field_name (str): Name of the erroneous field.
- reason (str): Reason for the failure.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
190class NoPrimaryFieldError(Exception): 191 """ 192 Thrown when a table model has not defined a primary field. See the 193 documentation of table.Table.primary_field() for more information on 194 declaring a primary field. 195 196 Args: 197 model_name (str): Name of the model. 198 """ 199 200 def __init__(self, model_name: str): 201 self.model_name = model_name 202 203 def __str__(self) -> str: 204 return f"the model {self.model_name} does not define a primary field"
Thrown when a table model has not defined a primary field. See the documentation of table.Table.primary_field() for more information on declaring a primary field.
Arguments:
- model_name (str): Name of the model.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
207class MultiplePrimaryFieldsError(Exception): 208 """ 209 Thrown when a table model has more than one primary field defined. Only one 210 is allowed. See the documentation of `table.Table.primary_field()` for more 211 information on declaring a primary field. 212 213 Args: 214 model_name (str): Name of the model. 215 """ 216 217 def __init__(self, model_name: str): 218 self.model_name = model_name 219 220 def __str__(self) -> str: 221 return f"the model {self.model_name} defines more than one primary field, only one is allowed"
Thrown when a table model has more than one primary field defined. Only one
is allowed. See the documentation of table.Table.primary_field()
for more
information on declaring a primary field.
Arguments:
- model_name (str): Name of the model.
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args