{"record":{"id":"e58b9f5a5ad36e74","repo":"BoundaryML/baml","slug":"failed-to-parse-float-0","errorCode":null,"errorMessage":"Failed to parse float: {0}","messagePattern":"Failed to parse float: (.+?)","errorType":"error_code","errorClass":"ConvertError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_sap/src/sap_model/convert.rs","lineNumber":24,"sourceCode":"use ::std::{\n    collections::{HashMap, HashSet},\n    sync::Arc,\n};\nuse ::sys_types::{ClassDefinition, DefKey, EnumDefinition, SapTy};\nuse indexmap::IndexMap;\n\nuse crate::sap_model::{\n    self, AnnotatedEnumVariant, AnnotatedField, AnnotatedTy, ArrayTy, AttrLiteral, BigintLiteralTy,\n    BigintTy, BoolLiteralTy, BoolTy, ClassTy, EnumTy, EnumVariantTy, FloatTy, IntLiteralTy, IntTy,\n    MapTy, MediaTy, NullTy, StringLiteralTy, StringTy, TyResolved, TyWithMeta, TypeAnnotations,\n    TypeRefDb, UnionTy,\n};\n\nimpl crate::sap_model::TypeIdent for DefKey {}\n\n#[derive(thiserror::Error, Debug)]\npub enum ConvertError {\n    #[error(\"Failed to parse float: {0}\")]\n    ParseFloat(#[from] std::num::ParseFloatError),\n    #[error(\"Unknown media kind\")]\n    UnknownMediaKind,\n    #[error(\"Float literals cannot be parsed\")]\n    FloatLiteral,\n    #[error(\"Non-parsable type: {0:?}\")]\n    NonParsableType(Box<SapTy>),\n    #[error(\"Unknown class: {0}\")]\n    UnknownClass(DefKey),\n    #[error(\"Unknown enum: {0}\")]\n    UnknownEnum(DefKey),\n    #[error(\"Unknown type alias: {0}\")]\n    UnknownTypeAlias(DefKey),\n    #[error(\"Unknown name (could not determine if it was a class, enum, or type alias): {0}\")]\n    UnknownName(DefKey),\n    #[error(\"Could not add a type to the database as the name `{0}` is already present\")]\n    AlreadyPresent(DefKey),\n    #[error(\"Recursion depth exceeded for {0}\")]","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_sap/src/sap_model/convert.rs#L6-L42","documentation":"`ConvertError::ParseFloat` wraps `std::num::ParseFloatError` and is thrown by the sap_model converter when a value that should be a float literal cannot be parsed into `f64`. It occurs during conversion of parsed SAP/BLP structures into the typed model when a numeric literal string is malformed.","triggerScenarios":"Converting a source tree (via the convert module) that contains a float literal token which `str::parse::<f64>()` rejects — e.g. an empty, malformed, or out-of-range numeric literal produced by an earlier lexing stage.","commonSituations":"A lexer change altered how numeric literals are tokenized (e.g. keeping suffixes or separators); source text written in a locale-dependent format (comma decimal separator); corrupted or hand-edited generated files.","solutions":["Inspect the wrapped ParseFloatError message to find the offending literal text, then fix the source literal.","Ensure the lexer strips non-numeric decoration (suffixes, separators) before conversion.","Normalize decimal separators (`,` -> `.`) in the token text before parsing.","Update bex_sap if this is a regression from a recent lexer/parser change."],"exampleFix":"// before\nlet f: f64 = tok.text.parse()?;\n// after\nlet normalized = tok.text.replace('_', \"\");\nlet f: f64 = normalized.parse().map_err(|e| ConvertError::ParseFloat(e))?;","handlingStrategy":"try-catch","validationCode":"fn is_valid_float_literal(s: &str) -> bool { s.replace('_', \"\").parse::<f64>().is_ok() }\n// check literal text before conversion","typeGuard":null,"tryCatchPattern":"match convert(tree) {\n    Ok(m) => m,\n    Err(ConvertError::ParseFloat(e)) => { eprintln!(\"bad float literal: {e}\"); relex_and_retry()? }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Normalize numeric literal text (strip separators/suffixes) before parse::<f64>().","Pin lexer and converter versions together to avoid drift.","Reject locale-formatted numbers at ingestion time."],"tags":["rust","parsing","type-conversion"],"backgroundTag":"invalid-argument-format","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}