{"record":{"id":"c40a4426fa6c1891","repo":"swc-project/swc","slug":"stringenum-cannot-determine-string-value-of-this","errorCode":null,"errorMessage":"StringEnum: Cannot determine string value of this variant","messagePattern":"StringEnum: Cannot determine string value of this variant","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/string_enum/src/lib.rs","lineNumber":113,"sourceCode":"    );\n\n    item.with_generics(i.generics.clone())\n}\n\nfn get_str_value(attrs: &[Attribute]) -> String {\n    // TODO: Accept multiline string\n    let docs: Vec<_> = attrs.iter().filter_map(doc_str).collect();\n    for raw_line in docs {\n        let line = raw_line.trim();\n        if line.starts_with('`') && line.ends_with('`') {\n            let mut s: String = line.split_at(1).1.into();\n            let new_len = s.len() - 1;\n            s.truncate(new_len);\n            return s;\n        }\n    }\n\n    panic!(\"StringEnum: Cannot determine string value of this variant\")\n}\n\nfn make_from_str(i: &DeriveInput) -> ItemImpl {\n    let arms = Binder::new_from(i)\n        .variants()\n        .into_iter()\n        .map(|v| {\n            // Qualified path of variant.\n            let qual_name = v.qual_path();\n\n            let str_value = get_str_value(v.attrs());\n\n            let mut pat: Pat = Pat::Lit(ExprLit {\n                attrs: Default::default(),\n                lit: Lit::Str(LitStr::new(&str_value, Span::call_site())),\n            });\n\n            // Handle `string_enum(alias(\"foo\"))`","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/string_enum/src/lib.rs#L95-L131","documentation":"Compile-time panic from `#[derive(StringEnum)]` (crates/string_enum). The macro derives the wire string for each variant by scanning its doc comments for a line that, after trimming, starts and ends with a backtick (e.g. `/// \\`use strict\\``); the value is the backticked content. If no doc line matches, the variant has no string value and the macro panics.","triggerScenarios":"A variant with no doc comment at all; a doc comment without backticks (`/// use strict`); prose docs where the backticked token is only part of the line (`/// indicates \\`strict\\` mode`).","commonSituations":"Adding new variants to string-mapped enums (e.g. source types, module kinds) and writing normal prose docs instead of the exact backtick convention; doc-formatters (rustfmt/doc comment style) altering the line.","solutions":["Add a doc line that is exactly the backticked value: `/// \\\"value\\\"` wrapped in backticks","Ensure the trimmed line both starts and ends with a backtick and stays on one line (multiline values are unsupported per the TODO)"],"exampleFix":"// before\n/// indicates script\nScript,\n\n// after\n/// `script`\nScript,","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give every StringEnum variant a one-line doc comment that is exactly the backticked value","Do not let prose share the line with the backticked token","Re-run `cargo check` after adding variants or after doc reformatting"],"tags":["rust","proc-macro","swc","string-enum","doc-comment","compile-time"],"backgroundTag":"proc-macro-misuse","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}