rohitg00/ai-engineering-from-scratch · error · ReliabilityError
charge must be positive
Error message
charge must be positive
What it means
Error "charge must be positive" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at phases/13-tools-and-protocols/29-mcp-reliability-cancellation-and-flow-control/code/main.py:335
@staticmethod
def _fingerprint(account: str, cents: int) -> str:
payload = json.dumps(
{"account": account, "cents": cents},
sort_keys=True,
separators=(",", ":"),
)
return hashlib.sha256(payload.encode("utf-8")).hexdigest()
def charge(
self,
account: str,
cents: int,
*,
rpc_id: int | str,
idempotency_key: str | None = None,
) -> dict[str, Any]:
if cents <= 0:
raise ReliabilityError("charge must be positive")
fingerprint = self._fingerprint(account, cents)
with self._lock:
self._connection.execute("BEGIN IMMEDIATE")
try:
if idempotency_key is not None:
stored = self._connection.execute(
"""
SELECT fingerprint, result_json
FROM idempotency_records
WHERE idempotency_key = ?
""",
(idempotency_key,),
).fetchone()
if stored is not None:
stored_fingerprint, stored_json = stored
if stored_fingerprint != fingerprint:
raise ReliabilityError(
"idempotency key was reused with different arguments"View on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at phases/13-tools-and-protocols/29-mcp-reliability-cancellation-and-flow-control/code/main.py:335 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/cba1e9c4b643e247.
Report an issue: GitHub.