{"record":{"id":"1579d6e059c61af9","repo":"tracel-ai/burn","slug":"expected-bool-handle-got","errorCode":null,"errorMessage":"Expected bool handle, got {}","messagePattern":"Expected bool handle, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/backend.rs","lineNumber":190,"sourceCode":"\n    fn float_tensor(handle: TensorHandle<Self::Handle>) -> FlexTensor {\n        match handle.handle {\n            HandleKind::Float(t) => t,\n            _ => panic!(\"Expected float handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn int_tensor(handle: TensorHandle<Self::Handle>) -> FlexTensor {\n        match handle.handle {\n            HandleKind::Int(t) => t,\n            _ => panic!(\"Expected int handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn bool_tensor(handle: TensorHandle<Self::Handle>) -> FlexTensor {\n        match handle.handle {\n            HandleKind::Bool(t) => t,\n            _ => panic!(\"Expected bool handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn quantized_tensor(handle: TensorHandle<Self::Handle>) -> FlexQTensor {\n        match handle.handle {\n            HandleKind::Quantized(t) => t,\n            _ => panic!(\"Expected quantized handle, got {}\", handle.handle.name()),\n        }\n    }\n\n    fn float_tensor_handle(tensor: FlexTensor) -> Self::Handle {\n        HandleKind::Float(tensor)\n    }\n\n    fn int_tensor_handle(tensor: FlexTensor) -> Self::Handle {\n        HandleKind::Int(tensor)\n    }\n","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/backend.rs#L172-L208","documentation":"`BackendIr::bool_tensor` for the Flex backend unwraps a `TensorHandle` expecting `HandleKind::Bool`. Any other handle kind triggers a panic with 'Expected bool handle, got <name>'. This keeps bool results (masks, comparisons) from being read from wrongly-typed handles.","triggerScenarios":"Calling `bool_tensor()` on a handle that holds Float/Int/Quantized — commonly when a comparison or mask op's kernel returned a non-bool handle (e.g. int-encoded mask) or the caller fetched the wrong output.","commonSituations":"Custom Flex comparison kernels emitting int/float handles instead of bool, or consuming a handle from the wrong tensor slot after an op with multiple outputs.","solutions":["Make the producing kernel return `HandleKind::Bool` for boolean results.","Match on the handle kind and convert explicitly (e.g. compare against zero to build a bool tensor) before use.","Check output-slot selection so the correct handle is passed to `bool_tensor`."],"exampleFix":"// before\nlet t = BackendIr::bool_tensor(handle); // panics: got int\n// after\nlet t = match handle.handle {\n    HandleKind::Bool(t) => t,\n    HandleKind::Int(i) => i.not_equal_elem(0), // build bool from mask\n    other => panic!(\"unexpected handle {}\", other.name()),\n};","handlingStrategy":"type-guard","validationCode":"if !matches!(handle.handle, HandleKind::Bool(_)) { /* route to correct converter */ }","typeGuard":"fn as_bool_handle(t: HandleKind<Flex>) -> Option<FlexTensor> {\n    match t { HandleKind::Bool(b) => Some(b), _ => None }\n}","tryCatchPattern":"let result = std::panic::catch_unwind(AssertUnwindSafe(|| Flex::bool_tensor(handle.clone())));\nmatch result {\n    Ok(t) => use_bool(t),\n    Err(_) => eprintln!(\"handle was not bool\"),\n}","preventionTips":["Ensure comparison/mask kernels return HandleKind::Bool, not int-encoded masks.","Select the correct output slot when ops have multiple outputs.","Narrow with match on HandleKind before calling dtype-specific converters."],"tags":["rust","backend","handle","dtype-mismatch","panic"],"backgroundTag":"tensor-dtype-mismatch","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}