denoland/deno · error · syn::Error
missing top-level #[webidl] attribute
Error message
missing top-level #[webidl] attribute
What it means
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.
Source
Thrown at libs/ops/webidl/mod.rs:29
use syn::DeriveInput;
use syn::Error;
use syn::Token;
use syn::parse::Parse;
use syn::parse::ParseStream;
use syn::parse2;
use syn::spanned::Spanned;
pub fn webidl(item: TokenStream) -> Result<TokenStream, Error> {
let input = parse2::<DeriveInput>(item)?;
let span = input.span();
let ident = input.ident;
let ident_string = ident.to_string();
let converter = input
.attrs
.into_iter()
.find_map(|attr| ConverterType::from_attribute(attr).transpose())
.ok_or_else(|| {
Error::new(span, "missing top-level #[webidl] attribute")
})??;
let out = match input.data {
Data::Struct(data) => match converter {
ConverterType::Dictionary => {
create_impl(ident, dictionary::get_body(ident_string, span, data)?)
}
ConverterType::Enum => {
return Err(Error::new(span, "Structs do not support enum converters"));
}
},
Data::Enum(data) => match converter {
ConverterType::Dictionary => {
return Err(Error::new(
span,
"Enums currently do not support dictionary converters",
));
}View on GitHub (pinned to 9ad36f7a2c)
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.
Example fix
// before
#[derive(WebIDL)]
struct ColorOptions { pub alpha: bool }
// after
#[derive(WebIDL)]
#[webidl(dictionary)]
struct ColorOptions { pub alpha: bool } Defensive patterns
Strategy: validation
Validate before calling
// Compile-time: `cargo check`. Every `#[derive(WebIDL)]` item needs exactly one // top-level `#[webidl(dictionary)]` or `#[webidl(enum)]` attribute on the item itself.
Prevention
- 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.
When it happens
Trigger: `#[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.
Common situations: 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.
Related errors
- derive(CppgcInherits) requires #[cppgc_inherits_from(BaseTyp
- Unnamed fields are currently not supported
- Unit fields are currently not supported
- variants with fields are not allowed for enum converters
- Structs do not support enum converters
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/3a18453802e6e062.
Report an issue: GitHub.