BoundaryML/baml · error · ConvertError
Unknown media kind
Error message
Unknown media kind
What it means
`ConvertError::UnknownMediaKind` is raised by the sap_model type converter when it encounters a media kind it does not recognize. During conversion of type expressions containing media (e.g. image/audio/video types), an unrecognized kind string has no mapping in the converter.
Solutions
- Check the media kind spelling in the source against the kinds supported by your bex_sap version.
- Upgrade bex_sap/baml_language so the converter recognizes the new media kind.
- Add a match arm for the new media kind in the converter if you maintain the crate.
- Fall back to a generic/string type if the media kind is not essential.
Example fix
// before
match kind {
MediaKind::Image => ...,
MediaKind::Audio => ...,
}
// after
match kind {
MediaKind::Image => ...,
MediaKind::Audio => ...,
MediaKind::Video => ..., // newly supported
other => return Err(ConvertError::UnknownMediaKind),
} Defensive patterns
Strategy: type-guard
Validate before calling
const SUPPORTED_MEDIA_KINDS: &[&str] = &["image", "audio", "video"];
fn media_kind_supported(k: &str) -> bool { SUPPORTED_MEDIA_KINDS.contains(&k) }
// check before conversion Type guard
fn as_known_media_kind(k: &MediaKind) -> Option<&MediaKind> {
matches!(k, MediaKind::Image | MediaKind::Audio | MediaKind::Video).then_some(k)
} Try / catch
match convert(ty) {
Ok(m) => m,
Err(ConvertError::UnknownMediaKind) => { eprintln!("media kind unsupported by this bex_sap version"); fallback_to_string_type(ty) }
Err(e) => return Err(e.into()),
} Prevention
- Upgrade bex_sap when using newly added media kinds.
- Validate media kind names against the supported list before conversion.
- Keep grammar and converter match arms in sync in CI.
When it happens
Trigger: Converting a SapTy containing a media variant whose kind (image, audio, etc.) is not one of the kinds `convert.rs` knows — e.g. a newly added media kind in the grammar not yet handled in the converter match.
Common situations: Using a new/experimental media type in BLP source with an older bex_sap version; a typo in a media kind name; grammar and converter versions drifting apart.
Related errors
- BamlSerde cannot be derived for enums, use…
- capture loss omitted kind
- capture loss omitted reason
- Could not unify Enum
- Enum does not exist
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/f595decff2a775fb.
Report an issue: GitHub.
Appendix: source
Thrown at baml_language/crates/bex_sap/src/sap_model/convert.rs:26
sync::Arc,
};
use ::sys_types::{ClassDefinition, DefKey, EnumDefinition, SapTy};
use indexmap::IndexMap;
use crate::sap_model::{
self, AnnotatedEnumVariant, AnnotatedField, AnnotatedTy, ArrayTy, AttrLiteral, BigintLiteralTy,
BigintTy, BoolLiteralTy, BoolTy, ClassTy, EnumTy, EnumVariantTy, FloatTy, IntLiteralTy, IntTy,
MapTy, MediaTy, NullTy, StringLiteralTy, StringTy, TyResolved, TyWithMeta, TypeAnnotations,
TypeRefDb, UnionTy,
};
impl crate::sap_model::TypeIdent for DefKey {}
#[derive(thiserror::Error, Debug)]
pub enum ConvertError {
#[error("Failed to parse float: {0}")]
ParseFloat(#[from] std::num::ParseFloatError),
#[error("Unknown media kind")]
UnknownMediaKind,
#[error("Float literals cannot be parsed")]
FloatLiteral,
#[error("Non-parsable type: {0:?}")]
NonParsableType(Box<SapTy>),
#[error("Unknown class: {0}")]
UnknownClass(DefKey),
#[error("Unknown enum: {0}")]
UnknownEnum(DefKey),
#[error("Unknown type alias: {0}")]
UnknownTypeAlias(DefKey),
#[error("Unknown name (could not determine if it was a class, enum, or type alias): {0}")]
UnknownName(DefKey),
#[error("Could not add a type to the database as the name `{0}` is already present")]
AlreadyPresent(DefKey),
#[error("Recursion depth exceeded for {0}")]
RecursionDepthExceeded(&'static str),
#[error("Unions must be flattened")]View on GitHub (pinned to bd85ce9dee)