{"record":{"id":"d9c546f0c1d457a6","repo":"linera-io/linera-protocol","slug":"count-exceeds-u32","errorCode":null,"errorMessage":"count exceeds u32","messagePattern":"count exceeds u32","errorType":"http","errorClass":"async_graphql::Error","httpStatus":null,"severity":"error","filePath":"linera-views/src/views/collection_view.rs","lineNumber":1830,"sourceCode":"\n    #[async_graphql::Object(cache_control(no_cache), name_type)]\n    impl<K, V> CollectionView<V::Context, K, V>\n    where\n        K: async_graphql::InputType\n            + async_graphql::OutputType\n            + serde::ser::Serialize\n            + serde::de::DeserializeOwned\n            + std::fmt::Debug,\n        V: View + async_graphql::OutputType,\n    {\n        async fn keys(&self) -> Result<Vec<K>, async_graphql::Error> {\n            Ok(self.indices().await?)\n        }\n\n        #[graphql(derived(name = \"count\"))]\n        async fn count_(&self) -> Result<u32, async_graphql::Error> {\n            let count = self.iterative_count().await?;\n            u32::try_from(count).map_err(|_| async_graphql::Error::new(\"count exceeds u32\"))\n        }\n\n        async fn entry(\n            &self,\n            key: K,\n        ) -> Result<Entry<K, ReadGuardedView<'_, V>>, async_graphql::Error> {\n            let value = self\n                .try_load_entry(&key)\n                .await?\n                .ok_or_else(|| missing_key_error(&key))?;\n            Ok(Entry { value, key })\n        }\n\n        async fn entries(\n            &self,\n            input: Option<MapInput<K>>,\n        ) -> Result<Vec<Entry<K, ReadGuardedView<'_, V>>>, async_graphql::Error> {\n            let keys = if let Some(keys) = input","sourceCodeStart":1812,"sourceCodeEnd":1848,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-views/src/views/collection_view.rs#L1812-L1848","documentation":"The GraphQL schema generated for `CollectionView` exposes a derived `count` field typed u32. The real entry count is a `usize` computed by iterating the view's index (`iterative_count`); if it exceeds `u32::MAX` (4,294,967,295) the conversion fails and the resolver returns 'count exceeds u32'. It is effectively an overflow guard for astronomically large collections, not an everyday error.","triggerScenarios":"Querying `count` on a CollectionView (e.g. an application's `users: CollectionView<_, Owner, RegisterView<_, ...>>`) holding more than 4,294,967,295 entries.","commonSituations":"Long-running, high-throughput applications writing one entry per operation without pruning; stress tests that inflate views to probe limits.","solutions":["Avoid `count` for huge views: page through `keys`/`entries` (with the `count`/filter arguments) and aggregate client-side if an exact total is not required.","Redesign the application state to bound growth — prune, bucket, or archive old entries into separate views or blobs.","Maintain an explicit counter (e.g. a RegisterView<u64>) updated on insert/remove instead of relying on the view's `count`.","If you truly need more than 2^32 entries, request an upstream schema change to widen the field; the current u32 cannot represent it."],"exampleFix":"# before\nquery { app { state { users { count } } } }  # errors once > u32::MAX entries\n\n# after\nquery { app { state { users { keys(count: 1000) } } } }  # page and tally client-side; or expose apps { userCount }","handlingStrategy":"fallback","validationCode":"# GraphQL: probe size cheaply before trusting `count`\nquery { app { state { users { keys(count: 1) } } } }  # returns at least the keys page without u32 risk","typeGuard":null,"tryCatchPattern":"try { return await gql.query('query { app { state { users { count } } } }'); } catch (e) { if (/count exceeds u32/i.test(e.message)) { const keys = await gql.query('query { app { state { users { keys } } } }'); return countKeysByPaging(keys); } throw e; }","preventionTips":["Don't expose raw collection `count` in user-facing UIs; maintain a RegisterView counter.","Prune or archive old entries so collections stay well under 2^32.","Prefer `keys`/`entries` with explicit paging for large views."],"tags":["graphql","views","count","u32-overflow","collection-view"],"backgroundTag":"integer-overflow","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}