What version are you using?
All versions, I've noticed this behaviour since inception.
What did you do?
Defined a contract with a user-defined error enum named Error and used it as the error type in a Result return type:
#[contracterror]
#[derive(Debug, PartialEq)]
pub enum Error {
Overflow = 1,
}
#[contractimpl]
impl Contract {
pub fn safe_add(a: u64, b: u64) -> Result<u64, Error> {
a.checked_add(b).ok_or(Error::Overflow)
}
}
Then imported this contract in another contract using contractimport! and attempted to use the generated client.
What did you expect to see?
The generated client code should reference the user-defined Error enum as a UDT:
fn try_safe_add(...) -> Result<..., Result<u64, Error>>
Where Error is the user-defined error enum with the Overflow variant.
What did you see instead?
The generated client code incorrectly uses the built-in soroban_sdk::Error type:
fn try_safe_add(...) -> Result<..., Result<u64, soroban_sdk::Error>>
This causes type mismatches when trying to match on the error variants, since soroban_sdk::Error doesn't have the user-defined Overflow variant.
Note: This only happens when the error enum is named exactly "Error". Using other names like "MyError" works correctly:
#[contracterror]
pub enum MyError {
Overflow = 1,
}
pub fn safe_add_two(a: u64, b: u64) -> Result<u64, MyError> { ... }
// Generated client correctly produces: Result<..., Result<u64, MyError>>
The issue is in soroban-sdk-macros/src/map_type.rs where there's a special case that maps any type named "Error" to ScSpecTypeDef::Error (the built-in error type), even when it's a user-defined error enum.
What version are you using?
All versions, I've noticed this behaviour since inception.
What did you do?
Defined a contract with a user-defined error enum named
Errorand used it as the error type in aResultreturn type:Then imported this contract in another contract using
contractimport!and attempted to use the generated client.What did you expect to see?
The generated client code should reference the user-defined
Errorenum as a UDT:Where
Erroris the user-defined error enum with theOverflowvariant.What did you see instead?
The generated client code incorrectly uses the built-in
soroban_sdk::Errortype:This causes type mismatches when trying to match on the error variants, since
soroban_sdk::Errordoesn't have the user-definedOverflowvariant.Note: This only happens when the error enum is named exactly "Error". Using other names like "MyError" works correctly:
The issue is in
soroban-sdk-macros/src/map_type.rswhere there's a special case that maps any type named "Error" toScSpecTypeDef::Error(the built-in error type), even when it's a user-defined error enum.