{"record":{"id":"8be6756c4eb0adca","repo":"leptos-rs/leptos","slug":"internal-error-entered-unreachable-code-8be675","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server_fn/src/response/mod.rs","lineNumber":91,"sourceCode":"\n    /// The `Location` header or (if none is set), the URL of the response.\n    fn location(&self) -> String;\n\n    /// Whether the response has the [`REDIRECT_HEADER`](crate::redirect::REDIRECT_HEADER) set.\n    fn has_redirect(&self) -> bool;\n}\n\n/// A mocked response type that can be used in place of the actual server response,\n/// when compiling for the browser.\n///\n/// ## Panics\n/// This always panics if its methods are called. It is used solely to stub out the\n/// server response type when compiling for the client.\npub struct BrowserMockRes;\n\nimpl<E> TryRes<E> for BrowserMockRes {\n    fn try_from_string(_content_type: &str, _data: String) -> Result<Self, E> {\n        unreachable!()\n    }\n\n    fn try_from_bytes(_content_type: &str, _data: Bytes) -> Result<Self, E> {\n        unreachable!()\n    }\n\n    fn try_from_stream(\n        _content_type: &str,\n        _data: impl Stream<Item = Result<Bytes, Bytes>>,\n    ) -> Result<Self, E> {\n        unreachable!()\n    }\n}\n\nimpl Res for BrowserMockRes {\n    fn error_response(_path: &str, _err: Bytes) -> Self {\n        unreachable!()\n    }","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/leptos-rs/leptos/blob/32d20f6c9d517451d77beb68d88c7716823dac41/server_fn/src/response/mod.rs#L73-L109","documentation":"BrowserMockRes::try_from_string() always panics with unreachable!(). Per the source docs, this type 'always panics if its methods are called' and exists solely to stub out the server response type when compiling for the client. Hitting this panic means code tried to construct a server response in a browser context where no real response can be built.","triggerScenarios":"Calling TryRes::try_from_string() on BrowserMockRes — constructing a server-fn HTTP response from a string while running client-side.","commonSituations":"Server response-building code executed in wasm builds; custom server fn return handling invoked from the client; build/feature misconfiguration in leptos apps.","solutions":["Ensure response construction happens only in server fn code running on the server.","On the client, let the framework handle the returned value instead of building an HTTP response.","Gate response-building helpers behind #[cfg(feature = \"server\")]."],"exampleFix":"// before\nlet res = BrowserMockRes::try_from_string(\"text/plain\", data)?;\n// after: build responses only in server fns\n#[server]\nfn handler() -> Result<String, ServerFnError> { Ok(data) }","handlingStrategy":"validation","validationCode":"if !cfg!(feature = \"server\") { return None; } // never construct server responses on client","typeGuard":"fn can_build_res() -> bool { cfg!(feature = \"server\") }","tryCatchPattern":"#[cfg(feature = \"server\")]\nlet res = TryRes::try_from_string(ct, data)?;","preventionTips":["Never call TryRes constructors outside server fn runtime code","Return plain data from server fns; let the server encode responses","Add client-side integration tests that would surface stub panics"],"tags":["panic","unreachable","server-fn","wasm","response-construction"],"backgroundTag":"browser-mock-stub-panic","analyzedSha":"32d20f6c9d517451d77beb68d88c7716823dac41","analyzedAt":"2026-09-01T18:55:42.580Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}