{"record":{"id":"3a18453802e6e062","repo":"denoland/deno","slug":"missing-top-level-webidl-attribute","errorCode":null,"errorMessage":"missing top-level #[webidl] attribute","messagePattern":"missing top-level #\\[webidl\\] attribute","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"libs/ops/webidl/mod.rs","lineNumber":29,"sourceCode":"use syn::DeriveInput;\nuse syn::Error;\nuse syn::Token;\nuse syn::parse::Parse;\nuse syn::parse::ParseStream;\nuse syn::parse2;\nuse syn::spanned::Spanned;\n\npub fn webidl(item: TokenStream) -> Result<TokenStream, Error> {\n  let input = parse2::<DeriveInput>(item)?;\n  let span = input.span();\n  let ident = input.ident;\n  let ident_string = ident.to_string();\n  let converter = input\n    .attrs\n    .into_iter()\n    .find_map(|attr| ConverterType::from_attribute(attr).transpose())\n    .ok_or_else(|| {\n      Error::new(span, \"missing top-level #[webidl] attribute\")\n    })??;\n\n  let out = match input.data {\n    Data::Struct(data) => match converter {\n      ConverterType::Dictionary => {\n        create_impl(ident, dictionary::get_body(ident_string, span, data)?)\n      }\n      ConverterType::Enum => {\n        return Err(Error::new(span, \"Structs do not support enum converters\"));\n      }\n    },\n    Data::Enum(data) => match converter {\n      ConverterType::Dictionary => {\n        return Err(Error::new(\n          span,\n          \"Enums currently do not support dictionary converters\",\n        ));\n      }","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/ops/webidl/mod.rs#L11-L47","documentation":"The `#[webidl(...)]`-driven derive in libs/ops/webidl/mod.rs scans the item's top-level attributes for one that yields a `ConverterType` (`webidl(dictionary)` or `webidl(enum)`). If none is found it raises this error on the whole item's span — the derive cannot know which converter to generate without the top-level attribute.","triggerScenarios":"`#[derive(WebIDL)]` (or the equivalent derive import) on a struct/enum without a top-level `#[webidl(dictionary)]` or `#[webidl(enum)]` attribute; also when the attribute is placed on a field instead of the item, or is misspelled.","commonSituations":"Adding the derive via IDE quick-fix without the helper attribute; moving the `#[webidl(...)]` attribute below the `#[derive(...)]` line so tooling strips it; typos such as `#[webidl]` (no converter argument) — note the bare form has no converter type either.","solutions":["Add a top-level attribute naming the converter: `#[webidl(dictionary)]` for structs, `#[webidl(enum)]` for enums.","Make sure the attribute sits directly on the type (above `#[derive(...)]` or next to it), not on a field or variant.","Check the spelling and argument — the attribute must be parsed by `ConverterType::from_attribute`, so `webidl` alone is not enough."],"exampleFix":"// before\n#[derive(WebIDL)]\nstruct ColorOptions { pub alpha: bool }\n\n// after\n#[derive(WebIDL)]\n#[webidl(dictionary)]\nstruct ColorOptions { pub alpha: bool }","handlingStrategy":"validation","validationCode":"// Compile-time: `cargo check`. Every `#[derive(WebIDL)]` item needs exactly one\n// top-level `#[webidl(dictionary)]` or `#[webidl(enum)]` attribute on the item itself.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write `#[derive(WebIDL)]` and the `#[webidl(...)]` attribute as one unit in templates/snippets.","Keep the webidl attribute on the item (not a field), and always with a converter argument."],"tags":["webidl","proc-macro","derive-macro","missing-attribute","compile-time"],"backgroundTag":"missing-macro-attribute","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}