{"record":{"id":"cba1e9c4b643e247","repo":"rohitg00/ai-engineering-from-scratch","slug":"charge-must-be-positive","errorCode":null,"errorMessage":"charge must be positive","messagePattern":"charge must be positive","errorType":"exception","errorClass":"ReliabilityError","httpStatus":null,"severity":"error","filePath":"phases/13-tools-and-protocols/29-mcp-reliability-cancellation-and-flow-control/code/main.py","lineNumber":335,"sourceCode":"    @staticmethod\n    def _fingerprint(account: str, cents: int) -> str:\n        payload = json.dumps(\n            {\"account\": account, \"cents\": cents},\n            sort_keys=True,\n            separators=(\",\", \":\"),\n        )\n        return hashlib.sha256(payload.encode(\"utf-8\")).hexdigest()\n\n    def charge(\n        self,\n        account: str,\n        cents: int,\n        *,\n        rpc_id: int | str,\n        idempotency_key: str | None = None,\n    ) -> dict[str, Any]:\n        if cents <= 0:\n            raise ReliabilityError(\"charge must be positive\")\n        fingerprint = self._fingerprint(account, cents)\n        with self._lock:\n            self._connection.execute(\"BEGIN IMMEDIATE\")\n            try:\n                if idempotency_key is not None:\n                    stored = self._connection.execute(\n                        \"\"\"\n                        SELECT fingerprint, result_json\n                        FROM idempotency_records\n                        WHERE idempotency_key = ?\n                        \"\"\",\n                        (idempotency_key,),\n                    ).fetchone()\n                    if stored is not None:\n                        stored_fingerprint, stored_json = stored\n                        if stored_fingerprint != fingerprint:\n                            raise ReliabilityError(\n                                \"idempotency key was reused with different arguments\"","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/13-tools-and-protocols/29-mcp-reliability-cancellation-and-flow-control/code/main.py#L317-L353","documentation":"Error \"charge must be positive\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"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.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}