Skip to content

fix: correct inverted balance/min_base values in OPG insufficient-balance error#219

Merged
adambalogh merged 1 commit intoOpenGradient:mainfrom
amathxbt:fix/opg-token-inverted-error-message
Apr 1, 2026
Merged

fix: correct inverted balance/min_base values in OPG insufficient-balance error#219
adambalogh merged 1 commit intoOpenGradient:mainfrom
amathxbt:fix/opg-token-inverted-error-message

Conversation

@amathxbt
Copy link
Copy Markdown
Contributor

🐛 Bug: Misleading Error Message in ensure_opg_approval

File: src/opengradient/client/opg_token.pyensure_opg_approval()

What's broken

On line 207, when the wallet balance is below the minimum required allowance, the error message displays the two values in the wrong order:

# Condition (L205): min_base > balance  →  balance < min_base
elif min_base > balance:
    raise ValueError(
        f"Wallet {owner} has less OPG tokens than the minimum allowance ({min_base} < {balance}). "
        #                                                                  ^^^^^^^^^^^^^^^^^^^^^^
        #                                                         WRONG: min_base < balance is False!

The printed comparison (min_base < {balance}) is logically inverted — the condition fires precisely when min_base > balance, so printing min_base < balance shows a false statement and confuses debugging.

Fix

Replace with a clear, accurate message that shows actual wallet balance vs. requirement:

raise ValueError(
    f"Wallet {owner} has insufficient OPG balance: "
    f"has {balance / 10**18:.6f} OPG, "
    f"but the minimum required is {min_base / 10**18:.6f} OPG. "
    f"Fund the wallet before approving."
)

Impact

Users encountering this error while debugging a low-balance issue would see a backwards comparison like (1000000000000000000 < 500000000000000000) — which appears to say they have more than enough, when they actually don't. This causes significant confusion and wasted debugging time.

Files Changed

  • src/opengradient/client/opg_token.py

@amathxbt
Copy link
Copy Markdown
Contributor Author

@adambalogh

@adambalogh adambalogh merged commit 0b7484e into OpenGradient:main Apr 1, 2026
4 checks passed
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.

2 participants