Skip to content

Log transaction errors#2345

Open
hubur wants to merge 2 commits intomainfrom
hbr.logging-tx-error
Open

Log transaction errors#2345
hubur wants to merge 2 commits intomainfrom
hbr.logging-tx-error

Conversation

@hubur
Copy link
Member

@hubur hubur commented Feb 3, 2026

A new kamiden endpoint to log tx errors

Summary by CodeRabbit

  • New Features
    • Added automatic transaction-error reporting: failed transactions are captured and sent to a configurable endpoint for diagnostics.
  • Bug Fixes / Reliability
    • Safer error normalization and JSON serialization (handles bigints and unexpected values) and non-throwing network/error handling.
  • Behavior
    • Action failure handling now triggers debug logging and error reporting when configured.

@vercel
Copy link

vercel bot commented Feb 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
kamigotchi-client Ready Ready Preview, Comment Feb 5, 2026 2:41pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

Walkthrough

Adds a new Kamiden transaction error logger and integrates it into the ActionSystem error handler to send normalized error payloads to a configured remote /tx-errors endpoint without throwing.

Changes

Cohort / File(s) Summary
Error Logging Infrastructure
packages/client/src/clients/kamiden/txErrorLogger.ts
New module implementing logTxError(error, context): Promise<void) with error normalization, safe JSON serialization (bigint handling), and POSTing payloads to {KAMIDEN_URL}/tx-errors.
Public Exports
packages/client/src/clients/kamiden/index.ts
Re-exports logTxError from ./txErrorLogger.
ActionSystem Integration
packages/client/src/network/systems/ActionSystem/createActionSystem.ts
Imports logTxError and invokes it from handleError after marking actions Failed; includes current account (sender) in the logging context and casts metadata to generic M when updating Failed state.

Sequence Diagram

sequenceDiagram
    participant Client
    participant ActionSystem
    participant AccountHook as useAccount()
    participant Logger as txErrorLogger
    participant Kamiden as Kamiden Service

    Client->>ActionSystem: transaction fails / throws
    ActionSystem->>ActionSystem: mark action as Failed
    ActionSystem->>AccountHook: read current account (sender)

    rect rgba(100,150,200,0.5)
    ActionSystem->>Logger: logTxError(error, { sender, system, method })
    Logger->>Logger: normalizeError(error)
    Logger->>Logger: build payload, safeStringify (bigint→string)
    end

    rect rgba(150,100,200,0.5)
    Logger->>Kamiden: POST {KAMIDEN_URL}/tx-errors (application/json)
    Kamiden-->>Logger: HTTP response (status, ok)
    Logger->>Logger: log response / errors (no throw)
    end

    Logger-->>ActionSystem: Promise<void>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • deeterbleater
  • ExistentialEnso
  • chlwys
  • JirAcheron
  • Xenofluxx

Poem

🐰 I hopped through logs at break of day,
Found bigints tangled in a fray,
I normalized each trembling bit,
Sent tales to Kamiden—every hit,
Now errors sleep while hops dance away.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title "Log transaction errors" directly and clearly describes the main objective of the pull request, which adds transaction error logging functionality across multiple files in the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hbr.logging-tx-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@packages/client/src/clients/kamiden/txErrorLogger.ts`:
- Around line 72-79: The payload sent in txErrorLogger.ts uses the raw error
which JSON.stringify may serialize to {} so message/stack are lost; call the
existing normalizeError(error) (or assign const normalized =
normalizeError(error)) and send that normalized object in the payload (e.g., use
normalized for the payload.error field) so the log includes message/stack/other
normalized properties; update references in the try block where payload is
constructed to use the normalized error shape.

In `@packages/client/src/network/systems/ActionSystem/createActionSystem.ts`:
- Around line 173-179: The error handler assumes useAccount.getState().account
exists and accesses account.operatorAddress, which can be undefined and crash;
update the createActionSystem error path to guard against a missing account by
fetching const account = useAccount.getState().account and using optional
chaining or an early guard (e.g., if (!account) { log.debug('[ActionSystem] No
account available for tx error', { action: action.action, description:
action.description }); return; }) before using account.operatorAddress, and when
calling logTxError pass sender: account?.operatorAddress ?? 'unknown' (or skip
sender) and keep system/method fallbacks using action.action ?? 'unknown' and
action.description ?? 'unknown'.

Comment on lines +173 to +179
const account = useAccount.getState().account;
log.debug('[ActionSystem] Logging tx error', { operatorAddress: account.operatorAddress, action: action.action, description: action.description });
if (account.operatorAddress) {
logTxError(error, {
sender: account.operatorAddress,
system: action.action ?? 'unknown',
method: action.description ?? 'unknown',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Guard against missing account to prevent crashes in the error handler.

useAccount.getState().account may be undefined in some flows; accessing .operatorAddress would throw and break error handling.

🛠️ Proposed fix
-    const account = useAccount.getState().account;
-    log.debug('[ActionSystem] Logging tx error', { operatorAddress: account.operatorAddress, action: action.action, description: action.description });
-    if (account.operatorAddress) {
+    const account = useAccount.getState().account;
+    const operatorAddress = account?.operatorAddress;
+    log.debug('[ActionSystem] Logging tx error', { operatorAddress, action: action.action, description: action.description });
+    if (operatorAddress) {
       logTxError(error, {
-        sender: account.operatorAddress,
+        sender: operatorAddress,
         system: action.action ?? 'unknown',
         method: action.description ?? 'unknown',
       });
     } else {
       log.warn('[ActionSystem] No operator address, skipping tx error logging');
     }
🤖 Prompt for AI Agents
In `@packages/client/src/network/systems/ActionSystem/createActionSystem.ts`
around lines 173 - 179, The error handler assumes useAccount.getState().account
exists and accesses account.operatorAddress, which can be undefined and crash;
update the createActionSystem error path to guard against a missing account by
fetching const account = useAccount.getState().account and using optional
chaining or an early guard (e.g., if (!account) { log.debug('[ActionSystem] No
account available for tx error', { action: action.action, description:
action.description }); return; }) before using account.operatorAddress, and when
calling logTxError pass sender: account?.operatorAddress ?? 'unknown' (or skip
sender) and keep system/method fallbacks using action.action ?? 'unknown' and
action.description ?? 'unknown'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant