Skip to content

Commit bdb1572

Browse files
committed
fix(tesla): make PrivateKeyError a LibraryError, not TeslaFleetError
A key-file failure is local to this library, not an upstream Fleet API error, so it belongs with SigningDisabled under LibraryError. Claude-Session: https://claude.ai/code/session_01D7girHWFLWBu78by9NL3qE
1 parent bb14366 commit bdb1572

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ owner-writable only (`0600`) from the start, with no write-then-chmod window,
178178
and concurrent creators fall back to reading the file that won the create
179179
race. If an existing key file can't be read, isn't valid PEM, is
180180
password-encrypted, or is the wrong key type, both raise `PrivateKeyError`
181-
(a `TeslaFleetError`) with a `reason` of `"unreadable"`, `"malformed"`,
182-
`"encrypted"`, or `"wrong_type"`.
181+
(a `LibraryError`, not a `TeslaFleetError` - it's a local key-file failure,
182+
not an upstream Fleet API error) with a `reason` of `"unreadable"`,
183+
`"malformed"`, `"encrypted"`, or `"wrong_type"`.
183184

184185
`VehicleBluetooth` keeps a held BLE connection alive during idle periods by
185186
default with a passive GATT read about every 20 seconds. Pass

‎tesla_fleet_api/exceptions.py‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -404,23 +404,6 @@ class DeviceUnexpectedResponse(TeslaFleetError):
404404
status = 540
405405

406406

407-
class PrivateKeyError(TeslaFleetError):
408-
"""An existing private key file could not be loaded as a usable key.
409-
410-
Raised by ``Tesla.get_private_key``/``get_rsa_private_key`` only for a
411-
known-existing key file's read/parse failure - key generation and the
412-
O_EXCL create-race fallback keep raising their original exceptions.
413-
``reason`` is one of ``"unreadable"`` (I/O failure), ``"malformed"`` (not
414-
valid PEM), ``"encrypted"`` (PEM requires a passphrase), or
415-
``"wrong_type"`` (loaded key is not the expected type).
416-
"""
417-
418-
def __init__(self, reason: str, message: str) -> None:
419-
self.reason = reason
420-
self.message = message
421-
super().__init__()
422-
423-
424407
class LibraryError(Exception):
425408
"""Errors related to this library."""
426409

@@ -442,6 +425,25 @@ def __init__(self) -> None:
442425
)
443426

444427

428+
class PrivateKeyError(LibraryError):
429+
"""An existing private key file could not be loaded as a usable key.
430+
431+
Raised by ``Tesla.get_private_key``/``get_rsa_private_key`` only for a
432+
known-existing key file's read/parse failure - key generation and the
433+
O_EXCL create-race fallback keep raising their original exceptions.
434+
``reason`` is one of ``"unreadable"`` (I/O failure), ``"malformed"`` (not
435+
valid PEM), ``"encrypted"`` (PEM requires a passphrase), or
436+
``"wrong_type"`` (loaded key is not the expected type). A local key-file
437+
failure, not an upstream Fleet API error, so this subclasses
438+
``LibraryError`` rather than ``TeslaFleetError``.
439+
"""
440+
441+
def __init__(self, reason: str, message: str) -> None:
442+
self.reason = reason
443+
self.message = message
444+
super().__init__(message)
445+
446+
445447
class SignedCommandRequired(TeslaFleetError):
446448
"""The requested action requires a signed command; the unsigned cloud API cannot actuate it.
447449

0 commit comments

Comments
 (0)