Closes errors explicitly when common pitfall mistakes made using embed fields are made.
@@ -678,10 +678,34 @@ class EntityFactoryComponentImpl(entity_factory.IEntityFactoryComponent):
if embed.fields:
field_payloads: data_binding.JSONArray = []
- for field in embed.fields:
+ for i, field in enumerate(embed.fields):
+
+ # Yep, this is technically two unreachable branches. However, this is an incredibly
+ # common mistake to make when working with embeds and not using a static type
+ # checker, so I have added these as additional safeguards for UX and ease
+ # of debugging. The case that there are `None` should be detected immediately by
+ # static type checkers, regardless.
+
+ name = str(field.name) if field.name is not None else None # type: ignore[unreachable]
+ value = str(field.name) if field.name is not None else None # type: ignore[unreachable]
+
+ if name is None:
+ raise TypeError(f"in embed.fields[{i}].name - cannot have `None`")
+ if not name:
+ raise TypeError(f"in embed.fields[{i}].name - cannot have empty string")
+ if not name.strip():
+ raise TypeError(f"in embed.fields[{i}].name - cannot have only whitespace")
+
+ if value is None:
+ raise TypeError(f"in embed.fields[{i}].value - cannot have `None`")
+ if not value:
+ raise TypeError(f"in embed.fields[{i}].value - cannot have empty string")
+ if not value.strip():
+ raise TypeError(f"in embed.fields[{i}].value - cannot have only whitespace")
+
# Name and value always have to be specified; we can always
# send a default `inline` value also just to keep this simpler.
- field_payloads.append({"name": field.name, "value": field.value, "inline": field.is_inline})
+ field_payloads.append({"name": name, "value": value, "inline": field.is_inline})
payload["fields"] = field_payloads
return payload, uploads
