{"record":{"id":"c39227fa08fcaa35","repo":"tracel-ai/burn","slug":"expected-int-handle-got","errorCode":null,"errorMessage":"Expected int handle, got {}","messagePattern":"Expected int handle, got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/backend.rs","lineNumber":183,"sourceCode":"    }\n\n    fn flush(_device: &Self::Device) {}\n}\n\nimpl BackendIr for Flex {\n    type Handle = HandleKind<Self>;\n\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 {","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/backend.rs#L165-L201","documentation":"`BackendIr::int_tensor` for the Flex backend unwraps a `TensorHandle` expecting `HandleKind::Int`. Any other handle kind causes a panic with 'Expected int handle, got <name>'. It is a boundary check so int ops never silently receive foreign handle types.","triggerScenarios":"Calling `int_tensor()` on a handle produced by a float/bool/quantized op — e.g. dispatch routed an int op's result from a kernel that yielded a Float handle, or the handle was built with `HandleKind::Float`.","commonSituations":"Custom Flex kernels returning float results for integer ops (e.g. index/argmax kernels accidentally float), or after refactors that renamed/moved handle constructors.","solutions":["Make the producing kernel return `HandleKind::Int` for int ops.","Match on the handle kind at the call site and convert (e.g. cast float -> int via a proper op) instead of panicking.","Verify the op registration maps the int op to a kernel with integer output dtype."],"exampleFix":"// before\nlet t = BackendIr::int_tensor(handle); // panics: got float\n// after\nlet t = match handle.handle {\n    HandleKind::Int(t) => t,\n    HandleKind::Float(f) => f.cast_to_int(), // explicit conversion\n    other => panic!(\"unexpected handle {}\", other.name()),\n};","handlingStrategy":"type-guard","validationCode":"if !matches!(handle.handle, HandleKind::Int(_)) { /* route to correct converter */ }","typeGuard":"fn as_int_handle(t: HandleKind<Flex>) -> Option<FlexTensor> {\n    match t { HandleKind::Int(i) => Some(i), _ => None }\n}","tryCatchPattern":"let result = std::panic::catch_unwind(AssertUnwindSafe(|| Flex::int_tensor(handle.clone())));\nmatch result {\n    Ok(t) => use_int(t),\n    Err(_) => eprintln!(\"handle was not int\"),\n}","preventionTips":["Verify integer kernels (argmax, indexing, shape ops) return HandleKind::Int.","Match on HandleKind and cast explicitly when a float result must become int.","Test custom ops end-to-end so output dtype mismatches surface in tests, not production."],"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"}