Translate spend errors from lib to InsufficientFundsError#95
Merged
Translate spend errors from lib to InsufficientFundsError#95
Conversation
swansontec
requested changes
Jul 2, 2025
src/MoneroEngine.ts
Outdated
| options | ||
| ) | ||
| } catch (e: any) { | ||
| } catch (error: any) { |
Contributor
There was a problem hiding this comment.
This should be catch (error: unknown), and then use if (error instanceof Error) prior to accessing error.message. Since the error instanceof Error check takes us back into type-land, we can also do error.message === 'Not enough spendables' instead of using cleaners - that's a valid property access at that point. Something more like this:
try {
} catch (error: unknown) {
if (!(error instanceof error)) {
throw new Error(String(error))
}
if (error.message === 'Not enough spendables') {
throw new InsufficientFundsError({
tokenId: PRIMARY_CURRENCY_TOKEN_ID
})
}
const regex = / Have (\d*\.?\d+) XMR; need (\d*\.?\d+) XMR./gm
const subst = `\nHave: $1 XMR.\nNeed: $2 XMR.`
const msgFormatted = error.message.replace(regex, subst)
throw new Error(msgFormatted)
}Also, isn't the "Have: $1 XMR.\nNeed: $2 XMR" error another case of insufficient funds?
swansontec
approved these changes
Jul 3, 2025
b625990 to
4707f8f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneDescription
none