-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust deserealize fails with Stack Overflow #2341
Comments
Hi, could you please firstly check whether it is related to frb or your JSON deserialize code? And could you please show Rust stacktrace during the panic |
I don't think this is a rust deserealize issue, as the Rust test succeeds. The data structure provides a test case that checks it. How can I add a stacktrace logging? I tried following in use flutter_rust_bridge::{frb, setup_default_user_utils};
use std::backtrace::Backtrace;
use std::cell::Cell;
use std::env;
pub mod api;
mod frb_generated;
thread_local! {
static BACKTRACE: Cell<Option<Backtrace>> = const { Cell::new(None) };
}
#[frb(init)]
pub fn init_app() {
env::set_var("RUST_BACKTRACE", "1");
setup_default_user_utils();
std::panic::set_hook(Box::new(|_| {
let trace = Backtrace::capture();
BACKTRACE.set(Some(trace));
}));
} and then the catch in deserealize: impl TrainingPlan {
#[frb(sync)]
pub fn test_deserialize(content: String) -> Result<Self, String> {
info!("<!> deserializing training plan: {}", content);
let result = panic::catch_unwind(|| {
serde_json::from_str(&content)
});
match result {
Ok(Ok(plan)) => Ok(plan),
Ok(Err(e)) => {
error!("Deserialization error: {}", e.to_string());
Err(e.to_string())
}
Err(e) => {
let b = BACKTRACE.take().unwrap();
error!("at panic:\n{}", b);
let err = format!("A panic occurred during deserialization: {e:?}");
error!("{}", err);
Err(err)
}
}
}
} No matter what, I don't get a stack trace. |
update:
|
stacktrace: https://cjycode.com/flutter_rust_bridge/guides/how-to/stack-trace (e.g. ensure you create a blank new project with default generated code etc) Based on your info, I guess there may be another reason: It is not because json deserialization, but because returning the nesting type. Again, with stack trace it will be clear to see what is going on. It would be great to have a minimal reproducible sample (e.g. if it is the nesting type problem, then we can produce a dozen line of code that reproduce it). |
I created a minimal library to reproduce an error https://github.com/poborin/frb_deserialize a command to execute:
|
Great! However, "minimal reproducible sample" often means to reduce to a minimal complexity. For example, in https://github.com/poborin/frb_deserialize/blob/main/rust/src/api/training_plan.rs, maybe it can be as short as: pub struct A {
field: Vec<A>,
}
pub fn f() -> A {
A { field: vec![A { field: vec![]]}
} i.e. remove whatever does not cause the problem, such as unneeded fields, json deserialization, etc |
I have updated the repo. It turns that deserializer fails with use flutter_rust_bridge::frb;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct TrainingPlan {
pub(crate) weeks: u8,
}
impl TrainingPlan {
#[frb(sync)]
pub fn test_deserialize(content: String) -> Result<Self, String> {
serde_json::from_str(&content).map_err(|e| e.to_string())
}
} {
"weeks": 10
} |
Hmm, do you mean it is a To isolate the problem, try
and also try to |
Describe the bug
I have a fairly simple data structure:
data structure
and the corresponding test data
test JSON
So, it's a small and simple document and the data structure. However, when I execute the
deserialize()
method in the web app e.g.It fails with the
Stack Overflow
exceptionSteps to reproduce
assets/test_data/training_plan.json
at the root of the project.pubspec.yaml
flutter run --web-header=Cross-Origin-Opener-Policy=same-origin --web-header=Cross-Origin-Embedder-Policy=require-corp
Logs
Expected behavior
No response
Generated binding code
No response
OS
MacOS
Version of
flutter_rust_bridge_codegen
2.4.0
Flutter info
Version of
clang++
19.1.0
Additional context
No response
The text was updated successfully, but these errors were encountered: