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

fix(schema): empty array name #2339

Merged
merged 1 commit into from
Aug 25, 2024
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
8 changes: 7 additions & 1 deletion crates/dojo-types/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@
Ty::Struct(s) => s.name.clone(),
Ty::Enum(e) => e.name.clone(),
Ty::Tuple(tys) => format!("({})", tys.iter().map(|ty| ty.name()).join(", ")),
Ty::Array(ty) => format!("Array<{}>", ty[0].name()),
Ty::Array(ty) => {
if let Some(inner) = ty.first() {
format!("Array<{}>", inner.name())
} else {
"Array".to_string()

Check warning on line 63 in crates/dojo-types/src/schema.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo-types/src/schema.rs#L63

Added line #L63 was not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we have an array without inner type?

Copy link
Collaborator Author

@Larkooo Larkooo Aug 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Ty is also used for values, like for arrays returned from GRPC. So we might have a model with an empty array, which in that case, would panic since we cannot get the inner type due to our array being empty

}
}
Ty::ByteArray(_) => "ByteArray".to_string(),
}
}
Expand Down
Loading