{"record":{"id":"c05ced7094d9401b","repo":"nautechsystems/nautilus_trader","slug":"invalid-optionkind-was-invalid","errorCode":null,"errorMessage":"Invalid `OptionKind`, was '{invalid}'","messagePattern":"Invalid `OptionKind`, was '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/databento/src/decode/primitives.rs","lineNumber":85,"sourceCode":"        'R' => Ok(BookAction::Clear),\n        // 'F' (Fill) and 'N' (None) are deliberately NOT book actions: fills\n        // are attribution records whose book impact arrives as the explicit\n        // Cancel/Modify of the same match event (`decode_mbo_msg` filters\n        // them out before calling this).\n        invalid => anyhow::bail!(\"Invalid `BookAction`, was '{invalid}'\"),\n    }\n}\n\n/// Parses a Databento option kind character into an `OptionKind` enum.\n///\n/// # Errors\n///\n/// Returns an error if `c` is not a valid `OptionKind` character.\npub fn parse_option_kind(c: c_char) -> anyhow::Result<OptionKind> {\n    match c as u8 as char {\n        'C' => Ok(OptionKind::Call),\n        'P' => Ok(OptionKind::Put),\n        invalid => anyhow::bail!(\"Invalid `OptionKind`, was '{invalid}'\"),\n    }\n}\n\npub(super) fn parse_currency_or_usd_default(\n    value: Result<&str, impl std::error::Error>,\n) -> Currency {\n    match value {\n        Ok(value) if !value.is_empty() => Currency::try_from_str(value).unwrap_or_else(|| {\n            log::warn!(\"Unknown currency code '{value}', defaulting to USD\");\n            Currency::USD()\n        }),\n        Ok(_) => Currency::USD(),\n        Err(e) => {\n            log::warn!(\"Error parsing currency: {e}\");\n            Currency::USD()\n        }\n    }\n}","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/databento/src/decode/primitives.rs#L67-L103","documentation":"parse_option_kind maps a Databento option-kind character (the call/put discriminant) to an OptionKind; any character outside the valid discriminant set fails here before the option contract is decoded.","triggerScenarios":"Decoding an option contract definition whose `option_kind` field is neither 'C' nor 'P' (e.g. empty, 'c'/'p' lowercase, or a placeholder char).","commonSituations":"Malformed instrument definition records; upstream schema changes; manually constructed test definitions with the wrong kind character; non-option records accidentally routed through option decoding.","solutions":["Verify the instrument definition's option_kind field is 'C' or 'P'","Check that the record really is an option contract (asset class / instrument_class)","Fix or regenerate corrupted definition data from Databento","Normalize case upstream if your data uses lowercase c/p"],"exampleFix":"// before\noption_kind: b'c'\n// after\noption_kind: b'C' // 'C' call or 'P' put only","handlingStrategy":"validation","validationCode":"fn is_valid_option_kind(c: u8) -> bool { matches!(c, b'C' | b'P') }\nfn validate_definition(def: &dbn::InstrumentDefMsg) -> Result<(), String> {\n    if def.instrument_class == dbn::InstrumentClass::Option && !is_valid_option_kind(def.option_kind as u8) {\n        return Err(format!(\"bad option_kind: {}\", def.option_kind));\n    }\n    Ok(())\n}","typeGuard":"fn is_call_or_put(c: u8) -> Option<OptionKindSide> { match c { b'C' => Some(Call), b'P' => Some(Put), _ => None } }","tryCatchPattern":"match decode_option_contract(def) {\n    Ok(c) => c,\n    Err(e) if e.to_string().contains(\"Invalid `OptionKind`\") => { /* skip non-option/malformed record */ }\n    Err(e) => return Err(e),\n}","preventionTips":["Confirm instrument_class is Option before option-kind decoding","Normalize kind chars to uppercase 'C'/'P' in your pipeline","Validate definitions before decoding contracts"],"tags":["rust","databento","options","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}