{"record":{"id":"03787119b16a4d9f","repo":"vercel/turborepo","slug":"unable-to-encode-s","errorCode":null,"errorMessage":"Unable to encode '{s}'","messagePattern":"Unable to encode '(.+?)'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/turborepo-lockfiles/src/berry/ser.rs","lineNumber":202,"sourceCode":"        if let Some(unplugged) = meta.unplugged {\n            add_line(\"unplugged\", unplugged);\n        }\n        if let Some(built) = meta.built {\n            add_line(\"built\", built);\n        }\n    }\n\n    builder.s\n}\n\nfn wrap_string(s: &str) -> Cow<'_, str> {\n    let simple_string = regex!(r#\"^[^-?:,\\]\\[{}#&*!|>'\"%@` \\t\\r\\n]([ \\t]*[^,\\]\\[{}:# \\t\\r\\n])*$\"#);\n    match simple_string.is_match(s) {\n        // Simple strings require no wrapping\n        true => Cow::from(s),\n        // Complex strings require wrapping\n        false => {\n            Cow::from(serde_json::to_string(s).unwrap_or_else(|_| panic!(\"Unable to encode '{s}'\")))\n        }\n    }\n}\n\n#[cfg(test)]\nmod test {\n    use pretty_assertions::assert_eq;\n\n    use super::*;\n\n    #[test]\n    fn test_metadata_display() {\n        let metadata = Metadata {\n            version: \"6\".into(),\n            cache_key: Some(\"8c0\".to_string()),\n        };\n        assert_eq!(\n            metadata.to_string(),","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/vercel/turborepo/blob/f9245100cf0d31d96628804ead485f6bf226e55a/crates/turborepo-lockfiles/src/berry/ser.rs#L184-L220","documentation":"While serializing yarn berry (v2+) lockfiles, wrap_string() decides whether a string can be written bare using a YAML-safety regex; complex strings are quoted via serde_json::to_string. Serializing a &str cannot fail, so the unwrap_or_else(panic! \"Unable to encode\") branch is effectively unreachable and exists only to satisfy the Result.","triggerScenarios":"No realistic trigger: it would require serde_json to fail while encoding a valid UTF-8 string slice. If observed, it indicates memory corruption or a serde_json bug, both extraordinary.","commonSituations":"Should not occur in practice; would surface as an abrupt process abort while turbo writes a berry lockfile during conversion.","solutions":["Upgrade turborepo — newer versions restructure or remove the unwrap","If it recurs, build with debug symbols, capture the failing string, and report an issue"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"let result = std::panic::catch_unwind(|| serialize_berry(lockfile));\nif result.is_err() {\n    // keep the original lockfile on disk and report — never half-write on panic\n}","preventionTips":["Run lockfile-writing conversions in a subprocess so panics cannot corrupt the CLI host","Back up yarn.lock (it is in git) before berry migrations so any panic is recoverable"],"tags":["rust","panic","yarn-berry","serialization","unreachable"],"backgroundTag":"rust-panic-invariant-violation","analyzedSha":"f9245100cf0d31d96628804ead485f6bf226e55a","analyzedAt":"2026-08-17T10:46:15.696Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}