-
Notifications
You must be signed in to change notification settings - Fork 189
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
refactor: remove unwraps #196
Changes from 7 commits
df35aa8
95297cc
bb791b2
ff5a2c3
2a3b46b
30d5c3c
46890f5
822d2be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,7 @@ impl SchemaBuilder { | |
id_to_field: &HashMap<i32, NestedFieldRef>, | ||
identifier_field_ids: impl Iterator<Item = i32>, | ||
) -> Result<()> { | ||
let id_to_parent = index_parents(r#struct); | ||
let id_to_parent = index_parents(r#struct)?; | ||
for identifier_field_id in identifier_field_ids { | ||
let field = id_to_field.get(&identifier_field_id).ok_or_else(|| { | ||
Error::new( | ||
|
@@ -406,7 +406,7 @@ pub fn index_by_id(r#struct: &StructType) -> Result<HashMap<i32, NestedFieldRef> | |
} | ||
|
||
/// Creates a field id to parent field id map. | ||
pub fn index_parents(r#struct: &StructType) -> HashMap<i32, i32> { | ||
pub fn index_parents(r#struct: &StructType) -> Result<HashMap<i32, i32>> { | ||
struct IndexByParent { | ||
parents: Vec<i32>, | ||
result: HashMap<i32, i32>, | ||
|
@@ -487,8 +487,8 @@ pub fn index_parents(r#struct: &StructType) -> HashMap<i32, i32> { | |
parents: vec![], | ||
result: HashMap::new(), | ||
}; | ||
visit_struct(r#struct, &mut index).unwrap(); | ||
index.result | ||
visit_struct(r#struct, &mut index)?; | ||
Ok(index.result) | ||
odysa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
#[derive(Default)] | ||
|
@@ -971,13 +971,13 @@ mod tests { | |
|
||
#[test] | ||
fn test_schema_display() { | ||
let expected_str = r#" | ||
let expected_str = " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to change this? I believe raw string is easier to read. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, it's clearer if we make whitespaces explicit. Also, my code formatter keeps removing the trailing whitespace. 🥲 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds reasonable, not a big problem to me. |
||
table { | ||
1: foo: optional string | ||
2: bar: required int | ||
3: baz: optional boolean | ||
1: foo: optional string\x20 | ||
2: bar: required int\x20 | ||
3: baz: optional boolean\x20 | ||
} | ||
"#; | ||
"; | ||
|
||
assert_eq!(expected_str, format!("\n{}", table_schema_simple().0)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the misinformation, in fact I mean all changes of unwrap in this file seems unnecessary to me, since they are all generated by internal code and they are expected to be safe.