Skip to content

Commit 6d67bc0

Browse files
committed
FIX: Fix exception chaining
1 parent 8bb77b0 commit 6d67bc0

File tree

8 files changed

+30
-30
lines changed

8 files changed

+30
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Changed `Live.__iter__()` and `Live.__aiter__()` to send the session start message if the session is connected but not started
99
- Upgraded `databento-dbn` to 0.7.1
1010
- Removed `Encoding`, `Compression`, `Schema`, and `SType` enums as they are now exposed by `databento-dbn`
11+
- Removed exception chaining from exceptions emitted by the library
1112

1213
#### Breaking changes
1314
- Renamed `func` parameter to `record_callback` for `Live.add_callback` and `Live.add_stream`

databento/common/dbnstore.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,9 @@ def replay(self, callback: Callable[[Any], None]) -> None:
789789
for record in self:
790790
try:
791791
callback(record)
792-
except Exception as exc:
792+
except Exception:
793793
logger.exception(
794794
"exception while replaying to user callback",
795-
exc_info=exc,
796795
)
797796
raise
798797

databento/common/enums.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ def coerced_new(enum: type[M], value: object) -> M:
6565
)
6666
try:
6767
return _new(enum, coerce_fn(value))
68-
except ValueError as ve:
68+
except ValueError:
6969
name_to_try = str(value).replace(".", "_").replace("-", "_").upper()
7070
named = enum._member_map_.get(name_to_try)
7171
if named is not None:
7272
return named
73-
enum_values = tuple(value for value in enum._value2member_map_)
73+
enum_values = list(value for value in enum._value2member_map_)
7474

7575
raise ValueError(
76-
f"value `{value}` is not a member of {enum_type.__name__}. "
77-
f"use one of {enum_values}.",
78-
) from ve
76+
f"The `{value}` was not a valid value of {enum_type.__name__}"
77+
f", was '{value}'. Use any of {enum_values}.",
78+
) from None
7979

8080
setattr(enum_type, "__new__", coerced_new)
8181

databento/common/validation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def validate_path(value: PathLike[str] | str, param: str) -> Path:
3030
"""
3131
try:
3232
return Path(value)
33-
except TypeError as e:
33+
except TypeError:
3434
raise TypeError(
3535
f"The `{param}` was not a valid path type. "
3636
"Use any of [str, bytes, os.PathLike].",
37-
) from e
37+
) from None
3838

3939

4040
def validate_enum(
@@ -68,16 +68,16 @@ def validate_enum(
6868
"""
6969
try:
7070
return enum(value)
71-
except ValueError as e:
71+
except ValueError:
7272
if hasattr(enum, "variants"):
7373
valid = list(map(str, enum.variants())) # type: ignore [attr-defined]
7474
else:
7575
valid = list(map(str, enum))
7676

7777
raise ValueError(
78-
f"The `{param}` was not a valid value of {enum}, was '{value}'. "
79-
f"Use any of {valid}.",
80-
) from e
78+
f"The `{param}` was not a valid value of {enum.__name__}"
79+
f", was '{value}'. Use any of {valid}.",
80+
) from None
8181

8282

8383
def validate_maybe_enum(

databento/live/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ def block_for_close(
527527
self.terminate()
528528
if isinstance(exc, KeyboardInterrupt):
529529
raise
530-
except Exception as exc:
530+
except Exception:
531531
logger.exception("exception encountered blocking for close")
532-
raise BentoError("connection lost") from exc
532+
raise BentoError("connection lost") from None
533533

534534
async def wait_for_close(
535535
self,
@@ -572,9 +572,9 @@ async def wait_for_close(
572572
self.terminate()
573573
if isinstance(exc, KeyboardInterrupt):
574574
raise
575-
except Exception as exc:
575+
except Exception:
576576
logger.exception("exception encountered waiting for close")
577-
raise BentoError("connection lost") from exc
577+
raise BentoError("connection lost") from None
578578

579579
async def _shutdown(self) -> None:
580580
"""

databento/live/gateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def parse(cls: type[T], line: str) -> T:
4949

5050
try:
5151
return cls(**data_dict)
52-
except TypeError as type_err:
52+
except TypeError:
5353
raise ValueError(
5454
f"`{line.strip()} is not a parsible {cls.__name__}",
55-
) from type_err
55+
) from None
5656

5757
def __str__(self) -> str:
5858
fields = tuple(map(attrgetter("name"), dataclasses.fields(self)))

databento/live/session.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,15 +500,15 @@ async def _connect_task(
500500
),
501501
timeout=CONNECT_TIMEOUT_SECONDS,
502502
)
503-
except asyncio.TimeoutError as exc:
503+
except asyncio.TimeoutError:
504504
raise BentoError(
505505
f"Connection to {gateway}:{port} timed out after "
506506
f"{CONNECT_TIMEOUT_SECONDS} second(s).",
507-
) from exc
507+
) from None
508508
except OSError as exc:
509509
raise BentoError(
510-
f"Connection to {gateway}:{port} failed.",
511-
) from exc
510+
f"Connection to {gateway}:{port} failed: {exc}",
511+
) from None
512512

513513
logger.debug(
514514
"connected to %s:%d",
@@ -521,13 +521,13 @@ async def _connect_task(
521521
protocol.authenticated,
522522
timeout=AUTH_TIMEOUT_SECONDS,
523523
)
524-
except asyncio.TimeoutError as exc:
524+
except asyncio.TimeoutError:
525525
raise BentoError(
526526
f"Authentication with {gateway}:{port} timed out after "
527527
f"{AUTH_TIMEOUT_SECONDS} second(s).",
528-
) from exc
528+
) from None
529529
except ValueError as exc:
530-
raise BentoError(f"User authentication failed: {str(exc)}") from exc
530+
raise BentoError(f"User authentication failed: {str(exc)}") from None
531531

532532
logger.info(
533533
"authentication with remote gateway completed",

tests/test_release.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ def test_release_changelog(changelog: str) -> None:
4545
try:
4646
versions = list(map(operator.itemgetter(0), releases))
4747
version_tuples = [tuple(map(int, v.split("."))) for v in versions]
48-
except Exception as exc:
48+
except Exception:
4949
# This could happen if we have an irregular version string.
50-
raise AssertionError("Failed to parse version from CHANGELOG.md") from exc
50+
raise AssertionError("Failed to parse version from CHANGELOG.md")
5151

5252
try:
5353
date_strings = list(map(operator.itemgetter(1), releases))
5454
dates = list(map(date.fromisoformat, date_strings))
55-
except Exception as exc:
55+
except Exception:
5656
# This could happen if we have TBD as the release date.
57-
raise AssertionError("Failed to parse release date from CHANGELOG.md") from exc
57+
raise AssertionError("Failed to parse release date from CHANGELOG.md")
5858

5959
# Ensure latest version matches `__version__`
6060
assert databento.__version__ == versions[0]

0 commit comments

Comments
 (0)