Skip to content

Commit

Permalink
Cleanup yaml file if its invalid (#4242)
Browse files Browse the repository at this point in the history
* Cleanup yaml file if its invalid

* FMT
  • Loading branch information
gupnik authored Jan 28, 2025
1 parent 6adb32d commit d08dfdd
Showing 1 changed file with 17 additions and 4 deletions.
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

0 comments on commit d08dfdd

Please sign in to comment.