{"record":{"id":"42626e11bfeb5ccb","repo":"BoundaryML/baml","slug":"no-collection-to-consume-token-0","errorCode":null,"errorMessage":"No collection to consume token: {0:?}","messagePattern":"No collection to consume token: (.+?)","errorType":"error_code","errorClass":"JsonishError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_sap/src/jsonish/mod.rs","lineNumber":23,"sourceCode":"\nmod parser;\nmod value;\n\npub use parser::{ParseOptions, parse};\npub use value::{CompletionState, Fixes, Value};\n\n/// Error type for jsonish parsing failures.\n#[derive(Debug, thiserror::Error)]\npub enum JsonishError {\n    #[error(\"Depth limit reached. Likely a circular reference.\")]\n    DepthLimitReached,\n    #[error(\"No JSON objects found\")]\n    NoJsonObjectsFound,\n    #[error(\"No markdown blocks found\")]\n    NoMarkdownBlocksFound,\n    #[error(\"Mismatched brackets\")]\n    MismatchedBrackets,\n    #[error(\"No collection to consume token: {0:?}\")]\n    NoCollectionForToken(char),\n    #[error(\"Failed to parse JSON\")]\n    ParseFailed,\n}\n","sourceCodeStart":5,"sourceCodeEnd":28,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_sap/src/jsonish/mod.rs#L5-L28","documentation":"`JsonishError::NoCollectionForToken(char)` is raised when the tokenizer/consumer encounters a collection-opening token (an object or array delimiter) while no collection is currently open on the parse stack — the input has a stray closing delimiter or an orphaned token with nothing to attach to. The `char` payload identifies the offending token.","triggerScenarios":"Calling `bex_sap::jsonish::parse` on text with stray `}`, `]`, or similar delimiters outside any open `{`/`[` — e.g. fragments of JSON mixed into prose.","commonSituations":"The model emits partial JSON fragments or code samples containing braces; a regex-based pre-extraction step cut the JSON in the wrong place leaving orphaned delimiters.","solutions":["Examine the reported character's position in the input and remove the stray delimiter or restore the missing opening one.","Improve pre-extraction so it slices complete JSON objects, not fragments.","Ask the model for a single complete JSON value with no surrounding code samples.","Add a validation/sanitizing step before parsing to drop obviously incomplete fragments."],"exampleFix":"// before\nlet v = jsonish::parse(frag, &opts)?; // frag: \"...} ]\"\n// after\nlet frag = extract_first_complete_object(&raw).ok_or(MyErr::NoJson)?;\nlet v = jsonish::parse(&frag, &opts)?;","handlingStrategy":"validation","validationCode":"fn has_orphan_closers(s: &str) -> bool {\n    let mut d = 0i32;\n    for c in s.chars() {\n        match c { '{' | '[' => d += 1, '}' | ']' => { d -= 1; if d < 0 { return true } }, _ => {} }\n    }\n    false\n}\n// if has_orphan_closers(raw), fix extraction boundaries first","typeGuard":null,"tryCatchPattern":"match jsonish::parse(&frag, &opts) {\n    Ok(v) => Ok(v),\n    Err(JsonishError::NoCollectionForToken(c)) => Err(format!(\"stray '{c}' — fix extraction slice\")),\n    Err(e) => Err(e.into()),\n}","preventionTips":["Slice complete JSON objects, not fragments, during pre-extraction.","Exclude code samples from candidate extraction ranges.","Run a delimiter-balance check before parsing."],"tags":["parsing","json","syntax"],"backgroundTag":"json-parse-error","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}