{"record":{"id":"7bca793fe6d1a1ed","repo":"clockworklabs/SpacetimeDB","slug":"dbconnectionbuilder-can-only-register-a-single-on","errorCode":null,"errorMessage":"DbConnectionBuilder can only register a single `on_connect` callback.\n\nInstead of registering multiple `on_connect` callbacks, register a single callback which does multiple operations.","messagePattern":"DbConnectionBuilder can only register a single `on_connect` callback\\.\n\nInstead of registering multiple `on_connect` callbacks, register a single callback which does multiple operations\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/rust/src/db_connection.rs","lineNumber":1146,"sourceCode":"    /// multiple `DbConnection`s writing to the same debug file concurrently\n    /// may interleave or corrupt the output.\n    pub fn with_debug_to_file(mut self, path: impl Into<PathBuf>) -> Self {\n        self.additional_logging_path = Some(path.into());\n        self\n    }\n\n    /// Register a callback to run when the connection is successfully established.\n    ///\n    /// The connection is established after the initial connection message is\n    /// received from the host. The callback will receive three arguments:\n    /// - The `DbConnection` which has successfully connected.\n    /// - The `Identity` of the successful connection.\n    /// - The private access token which can be used to later re-authenticate as the same `Identity`.\n    ///   If a token was passed to [`Self::with_token`],\n    ///   this will be the same token.\n    pub fn on_connect(mut self, callback: impl FnOnce(&M::DbConnection, Identity, &str) + Send + 'static) -> Self {\n        if self.on_connect.is_some() {\n            panic!(\n                \"DbConnectionBuilder can only register a single `on_connect` callback.\n\nInstead of registering multiple `on_connect` callbacks, register a single callback which does multiple operations.\"\n            );\n        }\n\n        self.on_connect = Some(Box::new(callback));\n        self\n    }\n\n    /// Register a callback to run when a connection attempt fails asynchronously.\n    ///\n    /// This callback is invoked only before the initial connection message is\n    /// received from the host. Errors which prevent [`Self::build`] from creating\n    /// a connection are returned by [`Self::build`] instead.\n    pub fn on_connect_error(mut self, callback: impl FnOnce(&M::ErrorContext, crate::Error) + Send + 'static) -> Self {\n        if self.on_connect_error.is_some() {\n            panic!(","sourceCodeStart":1128,"sourceCodeEnd":1164,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/sdks/rust/src/db_connection.rs#L1128-L1164","documentation":"Error \"DbConnectionBuilder can only register a single `on_connect` callback.\n\nInstead of registering multiple `on_connect` callbacks, register a single callback which does multiple operations.\" thrown in clockworklabs/SpacetimeDB.","triggerScenarios":"Thrown at sdks/rust/src/db_connection.rs:1146 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}