Skip to content
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

Cleanup yaml file if its invalid #4242

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions rust/tw_macros/src/tw_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,23 @@ pub fn tw_ffi(attr: TokenStream2, item: TokenStream2) -> Result<TokenStream2> {
let yaml_file_path = bindings_dir.join(format!("{}.yaml", class));

let mut config = if yaml_file_path.exists() {
serde_yaml::from_str(
&fs::read_to_string(&yaml_file_path).expect("Failed to read existing YAML file"),
)
.expect("Failed to parse YAML file")
match fs::read_to_string(&yaml_file_path) {
Ok(contents) => match serde_yaml::from_str(&contents) {
Ok(config) => config,
Err(_) => {
fs::remove_file(&yaml_file_path)
.expect("Failed to delete invalid YAML file");
TWConfig {
class,
static_functions: vec![],
}
},
},
Err(_) => TWConfig {
class,
static_functions: vec![],
},
}
} else {
TWConfig {
class,
Expand Down
Loading