non-trapping host functions for try_from_val
#1932
mootz12
started this conversation in
Core Advancement Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Context
In the
rs-soroban-sdk,try_from_valis expected to be a recoverable conversion API, but some generated SDK conversions still trap or panic for ordinary user-data shape mismatches.Generated
contracttypeconversions and some tuple conversions call host/env helpers such as:map_unpack_to_slicevec_unpack_to_slicesymbol_index_in_strsThese helpers currently report shape mismatches as host errors. Because
soroban_sdk::Envis intentionally infallible, those host errors trap or panic beforetry_from_valcan returnErr.This makes fallback logic unreliable, and is generally unexpected:
Proposal
Introduce new host functions whose successful return value can represent conversion failure.
Functions
All
try_conversion functions return the same ScError and Code, similar totry_call. Exact error is not super relevant. The error was chosen so the SDK can returnConversionError.SDK changes
Once these helpers exist, generated SDK conversions should use them during
try_from_val:contracttypestructs should usemap_unpack_to_slice_v2.try_vec.try_symbol_index_in_strs.TryFromValimplementations insoroban-env-commonshould also usevec_unpack_to_slice_v2.Alternatives
SDK-side preflight
The SDK can preflight some cases before calling the current helpers:
vec_unpack_to_slice,map_unpack_to_slice,symbol_index_in_strs.This works for some generated
contracttypecode, but it is incomplete and less efficient. It may not cover generic conversions insoroban-env-common, and map validation requires duplicating host-side logic.All reactions