Skip to content

Commit b09a52b

Browse files
committed
updated Exception classes
1 parent 54f56fe commit b09a52b

File tree

19 files changed

+326
-222
lines changed

19 files changed

+326
-222
lines changed

dlt/common/configuration/exceptions.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def __init__(self, spec_name: str, field_names: Sequence[str]) -> None:
122122
f"The config spec `{spec_name}` has dynamic type resolvers for fields: `{field_names}`"
123123
" but these fields are not defined in the spec.\nWhen using @resolve_type() decorator,"
124124
f" Add the fields with 'Any' or another common type hint, example:\n\n{example}"
125+
f"The config spec `{spec_name}` has dynamic type resolvers for fields: `{field_names}` but"
126+
" these fields are not defined in the spec.\nWhen using `@resolve_type()` decorator, Add"
127+
f" the fields with 'Any' or another common type hint, example:\n\n{example}"
125128
)
126129
super().__init__(msg)
127130

@@ -131,8 +134,7 @@ class FinalConfigFieldException(ConfigurationException):
131134

132135
def __init__(self, spec_name: str, field: str) -> None:
133136
super().__init__(
134-
f"Field `{field}` in spec `{spec_name}` is final but is being changed by a config"
135-
" provider"
137+
f"Field `{field}` in spec `{spec_name}` is final but is being changed by a config provider"
136138
)
137139

138140

@@ -144,7 +146,7 @@ def __init__(self, field_name: str, field_value: Any, hint: type) -> None:
144146
self.field_value = field_value
145147
self.hint = hint
146148
super().__init__(
147-
f"Can't coerce value for config field `{field_name}` into type {str(hint)}"
149+
f"Configured value for field {field_name} cannot be coerced into type {str(hint)}"
148150
)
149151

150152

@@ -172,7 +174,7 @@ def __init__(self, field_name: str, spec: Type[Any]) -> None:
172174
self.field_name = field_name
173175
self.typ_ = spec
174176
super().__init__(
175-
f"Field {field_name} on configspec {spec} does not provide required type hint"
177+
f"Field `{field_name}` on configspec `{spec}` does not provide required type hint"
176178
)
177179

178180

@@ -183,7 +185,7 @@ def __init__(self, field_name: str, spec: Type[Any], typ_: Type[Any]) -> None:
183185
self.field_name = field_name
184186
self.typ_ = spec
185187
super().__init__(
186-
f"Field {field_name} on configspec {spec} has hint with unsupported type {typ_}"
188+
f"Field `{field_name}` on configspec `{spec}` has hint with unsupported type `{typ_}`"
187189
)
188190

189191

@@ -192,7 +194,7 @@ def __init__(self, provider_name: str, key: str) -> None:
192194
self.provider_name = provider_name
193195
self.key = key
194196
super().__init__(
195-
f"Provider {provider_name} cannot hold secret values but key {key} with secret value is"
197+
f"Provider `{provider_name}` cannot hold secret values but key `{key}` with secret value is"
196198
" present"
197199
)
198200

@@ -211,10 +213,9 @@ def __init__(
211213
self.inner_exception = inner_exception
212214
inner_msg = f" {self.inner_exception}" if inner_exception is not ValueError else ""
213215
super().__init__(
214-
f"{spec.__name__} cannot parse the configuration value provided. The value is of type"
215-
f" {native_value_type.__name__} and comes from the"
216-
" {embedded_sections} section(s). Value may be a secret and is not shown. "
217-
f"Details: {inner_msg}"
216+
f"`{spec.__name__}` cannot parse the configuration value provided. The value is of type "
217+
f"`{native_value_type.__name__}` and comes from the sections `{embedded_sections}` "
218+
f"Value may be a secret and is not shown. Details: {inner_msg}"
218219
)
219220

220221

@@ -224,20 +225,20 @@ def __init__(self, spec: Type[Any], existing_config: Any, expected_config: Any)
224225
self.existing_config = existing_config
225226
self.expected_config = expected_config
226227
super().__init__(
227-
f"When restoring context {spec.__name__}, instance {expected_config} was expected,"
228-
f" instead instance {existing_config} was found."
228+
f"When restoring context `{spec.__name__}`, instance `{expected_config}` was expected,"
229+
f" instead instance `{existing_config}` was found."
229230
)
230231

231232

232233
class ContextDefaultCannotBeCreated(ContainerException, KeyError):
233234
def __init__(self, spec: Type[Any]) -> None:
234235
self.spec = spec
235-
super().__init__(f"Container cannot create the default value of context {spec.__name__}.")
236+
super().__init__(f"Container cannot create the default value of context `{spec.__name__}`.")
236237

237238

238239
class DuplicateConfigProviderException(ConfigProviderException):
239240
def __init__(self, provider_name: str) -> None:
240241
super().__init__(
241242
provider_name,
242-
f"Provider with name {provider_name} already present in ConfigProvidersContext",
243+
f"Provider with name `{provider_name}` already present in `ConfigProvidersContext`",
243244
)

dlt/common/configuration/specs/exceptions.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class OAuth2ScopesRequired(SpecException):
1010
def __init__(self, spec: type) -> None:
1111
self.spec = spec
1212
super().__init__(
13-
"Scopes are required to retrieve refresh_token. Use 'openid' scope for a token without"
13+
"Scopes are required to retrieve refresh_token. Use `openid` scope for a token without"
1414
" any permissions to resources."
1515
)
1616

@@ -26,27 +26,27 @@ class InvalidConnectionString(NativeValueError):
2626
def __init__(self, spec: Type[Any], native_value: str, driver: str):
2727
driver = driver or "driver"
2828
msg = (
29-
f"The expected representation for {spec.__name__} is a standard database connection"
30-
f" string with the following format: {driver}://username:password@host:port/database."
29+
f"The expected representation for `{spec.__name__}` is a standard database connection"
30+
f" string with the following format: `{driver}://username:password@host:port/database`"
3131
)
3232
super().__init__(spec, native_value, msg)
3333

3434

3535
class InvalidGoogleNativeCredentialsType(NativeValueError):
3636
def __init__(self, spec: Type[Any], native_value: Any):
3737
msg = (
38-
f"Credentials {spec.__name__} accept a string with serialized credentials json file or"
39-
" an instance of Credentials object from google.* namespace. The value passed is of"
40-
f" type {type(native_value)}"
38+
f"Credentials `{spec.__name__}` accept a string with serialized credentials json file or"
39+
" an instance of `Credentials` object from Google.* namespace. The value passed is of"
40+
f" type `{type(native_value)}`"
4141
)
4242
super().__init__(spec, native_value, msg)
4343

4444

4545
class InvalidGoogleServicesJson(NativeValueError):
4646
def __init__(self, spec: Type[Any], native_value: Any):
4747
msg = (
48-
f"The expected representation for {spec.__name__} is a string with serialized service"
49-
" account credentials, where at least 'project_id', 'private_key' and 'client_email`"
48+
f"The expected representation for `{spec.__name__}` is a string with serialized service"
49+
" account credentials, where at least `project_id`, `private_key` and `client_email`"
5050
" keys are present"
5151
)
5252
super().__init__(spec, native_value, msg)
@@ -55,7 +55,7 @@ def __init__(self, spec: Type[Any], native_value: Any):
5555
class InvalidGoogleOauth2Json(NativeValueError):
5656
def __init__(self, spec: Type[Any], native_value: Any):
5757
msg = (
58-
f"The expected representation for {spec.__name__} is a string with serialized oauth2"
58+
f"The expected representation for `{spec.__name__}` is a string with serialized oauth2"
5959
" user info and may be wrapped in 'install'/'web' node - depending of oauth2 app type."
6060
)
6161
super().__init__(spec, native_value, msg)
@@ -64,7 +64,7 @@ def __init__(self, spec: Type[Any], native_value: Any):
6464
class InvalidBoto3Session(NativeValueError):
6565
def __init__(self, spec: Type[Any], native_value: Any):
6666
msg = (
67-
f"The expected representation for {spec.__name__} is and instance of boto3.Session"
67+
f"The expected representation for `{spec.__name__}` is and instance of boto3.Session"
6868
" containing credentials"
6969
)
7070
super().__init__(spec, native_value, msg)

dlt/common/data_writers/exceptions.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@ class InvalidFileNameTemplateException(DataWriterException, ValueError):
1212
def __init__(self, file_name_template: str):
1313
self.file_name_template = file_name_template
1414
super().__init__(
15-
f"Wrong file name template {file_name_template}. File name template must contain"
15+
f"Wrong file name template `{file_name_template}`. File name template must contain"
1616
" exactly one %s formatter"
1717
)
1818

1919

2020
class BufferedDataWriterClosed(DataWriterException):
2121
def __init__(self, file_name: str):
2222
self.file_name = file_name
23-
super().__init__(f"Writer with recent file name {file_name} is already closed")
23+
super().__init__(f"Writer with recent file name `{file_name}` is already closed")
2424

2525

2626
class FileImportNotFound(DataWriterException, FileNotFoundError):
2727
def __init__(self, import_file_path: str, local_file_path: str) -> None:
2828
self.import_file_path = import_file_path
2929
self.local_file_path = local_file_path
3030
super().__init__(
31-
f"Attempt to import non existing file {import_file_path} into extract storage file"
32-
f" {local_file_path}"
31+
f"Attempt to import non existing file `{import_file_path}` into extract storage file"
32+
f" `{local_file_path}`"
3333
)
3434

3535

3636
class DestinationCapabilitiesRequired(DataWriterException, ValueError):
3737
def __init__(self, file_format: TLoaderFileFormat):
3838
self.file_format = file_format
3939
super().__init__(
40-
f"Writer for {file_format} requires destination capabilities which were not provided."
40+
f"Writer for `{file_format=:}` requires destination capabilities which were not provided."
4141
)
4242

4343

@@ -50,8 +50,7 @@ def __init__(self, file_format: TLoaderFileFormat, data_item_format: str):
5050
self.file_format = file_format
5151
self.data_item_format = data_item_format
5252
super().__init__(
53-
f"Can't find a file writer for file format {file_format} and item format"
54-
f" {data_item_format}"
53+
f"Can't find a file writer for `{file_format=:}` and item format `{data_item_format=:}`"
5554
)
5655

5756

@@ -60,8 +59,7 @@ def __init__(self, file_format: TLoaderFileFormat, data_item_format: str, spec:
6059
self.file_format = file_format
6160
self.data_item_format = data_item_format
6261
super().__init__(
63-
f"Can't find a file writer for spec with file format {file_format} and item format"
64-
f" {data_item_format} where the full spec is {spec}"
62+
f"Can't find a file writer for spec with `{file_format=:}` and `{data_item_format=:}` where the full spec is `{spec}`"
6563
)
6664

6765

@@ -76,8 +74,8 @@ def __init__(
7674
self.possible_file_formats = possible_file_formats
7775
self.data_item_format = data_item_format
7876
super().__init__(
79-
f"Lookup for best file writer for item format {data_item_format} among file formats"
80-
f" {possible_file_formats} failed. The preferred file format was {file_format}."
77+
f"Failed to find file writer for {data_item_format=:} among file formats"
78+
f" {possible_file_formats=:}. The preferred file format was `{file_format=:}`."
8179
)
8280

8381

@@ -86,5 +84,5 @@ def __init__(self, file_format: TLoaderFileFormat, data_item_format: str, detail
8684
self.file_format = file_format
8785
self.data_item_format = data_item_format
8886
super().__init__(
89-
f"A data item of type {data_item_format} cannot be written as {file_format}: {details}"
87+
f"A data item of type {data_item_format=:} cannot be written as `{file_format}: {details}`"
9088
)

0 commit comments

Comments
 (0)