Skip to content

Commit 8f3e757

Browse files
committed
Improve unsupported type error reporting
1 parent d779591 commit 8f3e757

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

rust/reflection/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ pub enum FlatbufferError {
5252
SetStringPolluted,
5353
#[error("Invalid schema: Polluted buffer or the schema doesn't match the buffer.")]
5454
InvalidSchema,
55-
#[error("Type not supported: {0}")]
56-
TypeNotSupported(String),
55+
#[error("Unsupported table field type: {0:?}")]
56+
UnsupportedTableFieldType(BaseType),
57+
#[error("Unsupported vector element type: {0:?}")]
58+
UnsupportedVectorElementType(BaseType),
59+
#[error("Unsupported union element type: {0:?}")]
60+
UnsupportedUnionElementType(BaseType),
5761
#[error("No type or invalid type found in union enum")]
5862
InvalidUnionEnum,
5963
#[error("Table or Struct doesn't belong to the buffer")]

rust/reflection/src/reflection_verifier.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,8 @@ fn verify_table(
154154
table_verifier
155155
}
156156
}
157-
_ => {
158-
return Err(FlatbufferError::TypeNotSupported(
159-
field
160-
.type_()
161-
.base_type()
162-
.variant_name()
163-
.unwrap_or_default()
164-
.to_string(),
165-
));
157+
other => {
158+
return Err(FlatbufferError::UnsupportedTableFieldType(other));
166159
}
167160
};
168161
}
@@ -340,15 +333,8 @@ fn verify_vector<'a, 'b, 'c>(
340333
}
341334
Ok(table_verifier)
342335
}
343-
_ => {
344-
return Err(FlatbufferError::TypeNotSupported(
345-
field
346-
.type_()
347-
.base_type()
348-
.variant_name()
349-
.unwrap_or_default()
350-
.to_string(),
351-
))
336+
other => {
337+
return Err(FlatbufferError::UnsupportedVectorElementType(other));
352338
}
353339
}
354340
}
@@ -399,14 +385,8 @@ fn verify_union<'a, 'b, 'c>(
399385
)?;
400386
}
401387
}
402-
_ => {
403-
return Err(FlatbufferError::TypeNotSupported(
404-
enum_type
405-
.base_type()
406-
.variant_name()
407-
.unwrap_or_default()
408-
.to_string(),
409-
))
388+
other => {
389+
return Err(FlatbufferError::UnsupportedUnionElementType(other));
410390
}
411391
}
412392
} else {

rust/reflection/src/struct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a> Struct<'a> {
3737
pub fn bytes(&self) -> &'a [u8] {
3838
&self.buf[self.loc..]
3939
}
40-
40+
4141
/// # Safety
4242
///
4343
/// [buf] must contain a valid struct at [loc]

0 commit comments

Comments
 (0)