{"record":{"id":"3324a38fb3545986","repo":"nautechsystems/nautilus_trader","slug":"invalid-uuid4-string","errorCode":null,"errorMessage":"Invalid UUID4 string","messagePattern":"Invalid UUID4 string","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/core/src/uuid.rs","lineNumber":200,"sourceCode":"    type Err = String;\n\n    /// Attempts to create a [`UUID4`] from a string representation.\n    ///\n    /// The string should be a valid UUID in the standard format (e.g., \"2d89666b-1a1e-4a75-b193-4eb3b454c757\").\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the `value` is not a valid UUID version 4 RFC 4122.\n    fn from_str(value: &str) -> Result<Self, Self::Err> {\n        let uuid = Uuid::try_parse(value).map_err(|e| e.to_string())?;\n        Self::try_validate_v4(&uuid)?;\n        Ok(Self::from_validated_uuid(&uuid))\n    }\n}\n\nimpl From<&str> for UUID4 {\n    fn from(value: &str) -> Self {\n        Self::from_str(value).expect(\"Invalid UUID4 string\")\n    }\n}\n\nimpl From<String> for UUID4 {\n    fn from(value: String) -> Self {\n        Self::from_str(&value).expect(\"Invalid UUID4 string\")\n    }\n}\n\nimpl From<uuid::Uuid> for UUID4 {\n    /// Creates a [`UUID4`] from a [`uuid::Uuid`].\n    ///\n    /// # Panics\n    ///\n    /// Panics if the `value` is not a valid UUID version 4 RFC 4122.\n    fn from(value: uuid::Uuid) -> Self {\n        Self::validate_v4(&value);\n        Self::from_validated_uuid(&value)","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/core/src/uuid.rs#L182-L218","documentation":"The `From<&str> for UUID4` impl parses the string with `from_str` and `.expect`s success, so any input that is not a valid UUID v4 string panics. The library intentionally treats a malformed UUID string as unrecoverable programmer error rather than a fallible parse.","triggerScenarios":"Calling `UUID4::from(some_str)` where `some_str` is not exactly a 36-char hyphenated UUID4 (e.g. `'abc'`, an empty string, a UUID without hyphens, or a non-v4 UUID variant/version).","commonSituations":"Passing user- or config-supplied IDs (order client IDs, external trade IDs) where a UUID4 is expected; reading truncated IDs from logs or CSV; storing UUIDs in a format that strips hyphens or uppercases braces.","solutions":["Use the fallible API `UUID4::from_str(value)` and handle the `Result` instead of `From::from`","Validate the string with the uuid crate (`uuid::Uuid::parse_str` and check version 4) before converting","Fix the data source so it emits canonical lowercase hyphenated UUID4 strings","If the value is an external identifier, model it as its own type (e.g. ClientOrderId) rather than forcing it into UUID4"],"exampleFix":"// before\nlet id = UUID4::from(config_value); // panics if malformed\n// after\nlet id = UUID4::from_str(config_value)\n    .unwrap_or_else(|e| panic!(\"invalid UUID4 in config: {e}\"));\n// or generate when absent\nlet id = config_value.map(UUID4::from_str).unwrap_or_else(|| Ok(UUID4::new()))?;","handlingStrategy":"validation","validationCode":"// Rust\nfn is_uuid4(s: &str) -> bool {\n    uuid::Uuid::parse_str(s).map(|u| u.get_version_num() == 4).unwrap_or(false)\n}","typeGuard":"fn try_uuid4(s: &str) -> Option<UUID4> { UUID4::from_str(s).ok() }","tryCatchPattern":"// Use the fallible API instead of From\nmatch UUID4::from_str(raw) {\n    Ok(id) => id,\n    Err(e) => { log::error!(\"bad UUID4 '{raw}': {e}\"); return Err(e.into()); }\n}","preventionTips":["Never feed external/user IDs into UUID4::from","Parse with from_str at system boundaries and reject bad input early","Generate IDs with UUID4::new() rather than parsing untrusted strings"],"tags":["rust","panic","uuid","parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}