cube-js/cube · error · syn::Error

Only trait can be annotated as a service

Error message

Only trait can be annotated as a service

What it means

The #[cuberpc::service] macro only transforms traits (it walks TraitItem::Method entries to generate RPC scaffolding), but it was applied to a non-trait item such as a struct, enum, or impl block. This is a compile-time authoring error in the annotated Rust source.

Source

Thrown at rust/cubestore/cuberpc/src/lib.rs:85

                    .iter()
                    .filter_map(|item| match item {
                        TraitItem::Method(method_item) => Some(RpcMethod {
                            ident: method_item.sig.ident.clone(),
                            args: method_item.sig.inputs.iter().cloned().collect::<Vec<_>>(),
                            output: method_item.sig.output.clone(),
                            asyncness: method_item.sig.asyncness.is_some(),
                        }),
                        _ => None,
                    })
                    .collect::<Vec<_>>();
                RpcService {
                    ident: trait_item.ident.clone(),
                    methods,
                    trace_guard: None,
                }
            }
            x => {
                return Err(syn::Error::new(
                    x.span(),
                    "Only trait can be annotated as a service",
                ))
            }
        };
        Ok(svc)
    }
}

impl RpcService {
    fn original_trait(&self) -> proc_macro2::TokenStream {
        let service_ident = &self.ident;
        let methods = self
            .methods
            .iter()
            .map(|m| m.original_method())
            .collect::<Vec<_>>();
        // TODO Supertraits

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Apply #[cuberpc::service] to a trait definition whose methods become the RPC surface
  2. Use the appropriate macro or plain code for non-trait items
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at rust/cubestore/cuberpc/src/lib.rs:85 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/3bee920af733d236. Report an issue: GitHub.