trustwallet / wallet-core

Cross-platform, cross-blockchain wallet library.
https://developer.trustwallet.com/wallet-core
Apache License 2.0
2.85k stars 1.6k forks source link

WalletCore Swallow exceptions , Make debugging much harder #3707

Open johnnyluo opened 8 months ago

johnnyluo commented 8 months ago

To be honest , I am not sure this should be a bug or a feature request Describe the bug I have been using WalletCore as a library in my own wallet app, and I am using it in IOS, swift and xcode, so I have been use it quite a lot recently , and find out WalletCore usually swallow all the exceptions, let me give you an example. The follow function , it catch all exceptions , and return empty instead, there is no logging , nothing

TWData *_Nonnull TWTransactionCompilerCompileWithSignatures(enum TWCoinType coinType, TWData *_Nonnull txInputData, const struct TWDataVector *_Nonnull signatures, const struct TWDataVector *_Nonnull publicKeys) {
    Data result;
    try {
        assert(txInputData != nullptr);
        const Data inputData = data(TWDataBytes(txInputData), TWDataSize(txInputData));
        assert(signatures != nullptr);
        const auto signaturesVec = createFromTWDataVector(signatures);
        assert(publicKeys != nullptr);
        const auto publicKeysVec = createFromTWDataVector(publicKeys);

        result  = TransactionCompiler::compileWithSignatures(coinType, inputData, signaturesVec, publicKeysVec);
    } catch (...) {} // return empty
    return TWDataCreateWithBytes(result.data(), result.size());
}

This make debug issues quite hard , at least it cost me a least more than a day to figure out why the function return empty bytes.

If the function can bubble up the exception , or error message will greatly help debugging. I raised it here in hope we could make it better

To Reproduce

Expected behavior bubble up the exceptions

Screenshots

Additional context

satoshiotomakan commented 8 months ago

Hi @johnnyluo, that's also right. We introduced an error system in Rust, but it's not available in C++ FFI yet. Hope we have time this year to work on it to improve UX.