denoland/deno · error · syn::Error

invalid attribute for `string` modifier

Error message

invalid attribute for `string` modifier

What it means

The `string` modifier on op2 parameters accepts exactly two forms: bare `#[string]` (default mode) or `#[string(onebyte)]`. The parser in libs/ops/op2/signature.rs first checks for the bare `Meta::Path` form, then tries `parse_args::<Ident>` equal to `onebyte`; anything else raises this error on the attribute span.

Source

Thrown at libs/ops/op2/signature.rs:1391

      } else {
        attr
          .parse_args()
          .map_err(AttributeError::InvalidAttribute)?
      };

      Some(AttributeModifier::WebIDL(args))
    }

    "string" => {
      if matches!(attr.meta, Meta::Path(_)) {
        Some(AttributeModifier::String(StringMode::Default))
      } else if attr
        .parse_args::<Ident>()
        .is_ok_and(|mode| mode == "onebyte")
      {
        Some(AttributeModifier::String(StringMode::OneByte))
      } else {
        return Err(AttributeError::InvalidAttribute(syn::Error::new(
          attr.span(),
          "invalid attribute for `string` modifier",
        )));
      }
    }

    buf @ "buffer" | buf @ "anybuffer" | buf @ "arraybuffer" => {
      let mode = if matches!(attr.meta, Meta::Path(_)) {
        BufferMode::Default
      } else {
        let ident: Ident = attr
          .parse_args()
          .map_err(AttributeError::InvalidAttribute)?;
        if ident == "unsafe" {
          BufferMode::Unsafe
        } else if ident == "copy" {
          BufferMode::Copy
        } else if ident == "detach" {

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Use `#[string]` for normal UTF-8 conversion, or `#[string(onebyte)]` when you specifically need a one-byte v8 string.
  2. Spell the argument exactly as the bare identifier `onebyte` — lowercase, no underscores, no quotes.

Example fix

// before
#[op2]
fn op_read(#[string(one_byte)] path: String) -> String { /* ... */ }

// after
#[op2]
fn op_read(#[string(onebyte)] path: String) -> String { /* ... */ }
Defensive patterns

Strategy: validation

Validate before calling

// Compile-time: `cargo check`. The closed form is:
//   #[string]            or    #[string(onebyte)]
// — nothing else parses.

Prevention

When it happens

Trigger: `#[string(utf8)]`, `#[string(twobyte)]`, `#[string("onebyte")]`, or `#[string(onebyte, extra)]` on an op parameter or return type.

Common situations: Assuming a general string-encoding modifier exists; misspelling `onebyte` (e.g. `oneByte`, `one_byte`); passing a string literal instead of the bare identifier.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/38f5a4f525d17b4d. Report an issue: GitHub.