uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

UniFFI-core: evaluation of constant value failed

Open JoFrost opened this issue 6 months ago • 2 comments

Hi there!

I'm working on an SDK that uses UniFFI (version 0.28.0) to export its code to Android and iOS. In this SDK, I have a large enum that lists all the possible errors a user might encounter.

After adding a few more error variants, I started encountering the following compile-time error:

error[E0080]: evaluation of constant value failed
   --> /home/snow/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/uniffi_core-0.28.0/src/metadata.rs:205:9
    |
205 |         assert!(self.size + string.len() + 1 < BUF_SIZE);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: self.size + string.len() + 1 < BUF_SIZE', /home/snow/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/uniffi_core-0.28.0/src/metadata.rs:205:9
    |
note: inside `MetadataBuffer::concat_long_str`
   --> /home/snow/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/uniffi_core-0.28.0/src/metadata.rs:205:9
    |
205 |         assert!(self.size + string.len() + 1 < BUF_SIZE);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `UNIFFI_META_CONST_SDK_FFI_ERROR_CLIENTERROR`
   --> bindings/sdk-ffi/src/error.rs:32:35
    |
32  | #[derive(Debug, thiserror::Error, uniffi::Error)]
    |                                   ^^^^^^^^^^^^^
    = note: this error originates in the macro `assert` which comes from the expansion of the derive macro `uniffi::Error` (in Nightly builds, run with -Z macro-backtrace for more info)

Unfortunately, reducing the number of errors or trimming down the documentation isn’t an option, this SDK is intended for production use, and comprehensive, documented error types are crucial for Android and iOS developers.

This seems closely related to the issue #1968, as I also have a large number of errors and substantial documentation.

Is there a way to increase the buffer size without modifying UniFFI’s source code? Are there any recommendations or workarounds I can apply to avoid this issue in the future?

Thanks!

JoFrost avatar May 09 '25 14:05 JoFrost

Sadly I can't think of any options other than the change made in #1968. It's probably fine to increase that value again, but that will require a change to the source.

mhammond avatar May 09 '25 15:05 mhammond

Thanks for your answer! I actually suspected that might be the case. I'll go ahead and open a PR to significantly increase the buffer size (I'm thinking 32k to ensure the issue doesn't come back). I'll also add support for making the buffer size configurable via an environment variable, so future adjustments can be made without modifying the code again. Let me know if that sounds good to you!

JoFrost avatar May 12 '25 07:05 JoFrost