lambdaclass / lambdaclass/eth-agent

Duplicate error handling pattern in safe wrapper methods

Open
#41 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code-quality low-priority
Dominant language
TypeScript
Stars
10
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Problem

The safeSend, safeSendUSDC, safeSendUSDT, etc. methods repeat the same error handling pattern.

Location

src/agent/wallet.ts - safeSend* methods

Current Pattern

async safeSendUSDC(...): Promise<SafeSendResult> {
  try {
    const result = await this.sendUSDC(...);
    return { success: true, result };
  } catch (error) {
    return { success: false, error: ... };
  }
}
// Repeated for each token type

Recommendation

Extract to a helper function or use a decorator pattern:

function wrapSafe<T>(fn: () => Promise<T>): Promise<SafeResult<T>> {
  try {
    const result = await fn();
    return { success: true, result };
  } catch (error) {
    return { success: false, error: normalizeError(error) };
  }
}

// Usage
safeSendUSDC = (...args) => wrapSafe(() => this.sendUSDC(...args));

Priority

Low - Code quality / DRY principle

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/agent/wallet.ts by reading the safeSend* methods and their corresponding send methods to compare the repeated error-handling behavior. Identify whether the existing result and error shapes can share one helper without changing public behavior. Done means the duplicated pattern is removed across the safe wrapper methods while successful sends and normalized failures remain equivalent.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.