{"record":{"id":"b87f9fac00643889","repo":"clockworklabs/SpacetimeDB","slug":"views-must-be-public-e-g-view-public","errorCode":null,"errorMessage":"views must be `public`, e.g. `#[view(public)]`","messagePattern":"views must be `public`, e\\.g\\. `#\\[view\\(public\\)\\]`","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/bindings-macro/src/view.rs","lineNumber":89,"sourceCode":"                    accessor = Some(meta.value()?.parse()?);\n                }\n                sym::primary_key => {\n                    check_duplicate_msg(&primary_key, &meta, \"`primary_key` already specified\")?;\n                    primary_key = Some(ViewPrimaryKeyArg::parse(meta.value()?)?);\n                }\n            });\n            Ok(())\n        })\n        .parse2(input)?;\n        let accessor = accessor.ok_or_else(|| {\n            let view = func_ident.to_string().to_snake_case();\n            syn::Error::new(\n                Span::call_site(),\n                format_args!(\"must specify view accessor, e.g. `#[spacetimedb::view(accessor = {view})]\"),\n            )\n        })?;\n        let () = public\n            .ok_or_else(|| syn::Error::new(Span::call_site(), \"views must be `public`, e.g. `#[view(public)]`\"))?;\n        Ok(Self {\n            name,\n            primary_key,\n            public: true,\n            accessor,\n        })\n    }\n}\n\n/// If `ty` is `impl Query<T>`, returns `Some(T)`. Otherwise `None`.\nfn extract_impl_query_inner(ty: &syn::Type) -> Option<&syn::Type> {\n    if let syn::Type::ImplTrait(impl_trait) = ty {\n        for bound in &impl_trait.bounds {\n            if let syn::TypeParamBound::Trait(trait_bound) = bound\n                && let Some(seg) = trait_bound.path.segments.last()\n                && seg.ident == \"Query\"\n                && let syn::PathArguments::AngleBracketed(args) = &seg.arguments\n                && let Some(syn::GenericArgument::Type(inner)) = args.args.first()","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-macro/src/view.rs#L71-L107","documentation":"Compile-time error from the #[spacetimedb::view] macro, raised right after the accessor check: every SpacetimeDB view must currently be public, so when the attribute list lacks the public flag the macro refuses to expand rather than defaulting to private. It is reported at the attribute's call site.","triggerScenarios":"Declaring a view whose attribute list has accessor = ... but not the word public, e.g. #[spacetimedb::view(accessor = person)].","commonSituations":"Authors expecting a private default for views; converting a query helper into a view and carrying over only the accessor argument; writing pub or pub(crate) instead of public inside the attribute (unknown words are ignored).","solutions":["Add the public flag: #[spacetimedb::view(public, accessor = person)].","If you wanted a non-public view, note the macro currently requires public on all views - keep it as a plain query helper instead."],"exampleFix":"// before\n#[spacetimedb::view(accessor = person)]\n\n// after\n#[spacetimedb::view(public, accessor = person)]","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Every #[spacetimedb::view] needs the public flag - write public and accessor = ... together as a pair.","Run cargo check right after adding a view so both view macro diagnostics surface in one pass."],"tags":["rust","proc-macro","spacetimedb","view","compile-time"],"backgroundTag":"missing-required-attribute","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}