{"record":{"id":"a6a2c41ee7b9ffa5","repo":"linera-io/linera-protocol","slug":"application-parameters-must-be-deserializable","errorCode":null,"errorMessage":"Application parameters must be deserializable","messagePattern":"Application parameters must be deserializable","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"linera-sdk/src/contract/runtime.rs","lineNumber":83,"sourceCode":"    }\n\n    /// Returns a storage context suitable for a root view.\n    pub fn root_view_storage_context(&self) -> ViewStorageContext {\n        ViewStorageContext::new_unchecked(self.key_value_store(), Vec::new(), ())\n    }\n}\n\nimpl<Application> ContractRuntime<Application>\nwhere\n    Application: Contract,\n{\n    /// Returns the application parameters provided when the application was created.\n    pub fn application_parameters(&mut self) -> Application::Parameters {\n        self.application_parameters\n            .get_or_insert_with(|| {\n                let bytes = base_wit::application_parameters();\n                serde_json::from_slice(&bytes)\n                    .expect(\"Application parameters must be deserializable\")\n            })\n            .clone()\n    }\n\n    /// Returns the ID of the current application.\n    pub fn application_id(&mut self) -> ApplicationId<Application::Abi> {\n        *self\n            .application_id\n            .get_or_insert_with(|| ApplicationId::from(base_wit::get_application_id()).with_abi())\n    }\n\n    /// Returns the chain ID of the current application creator.\n    pub fn application_creator_chain_id(&mut self) -> ChainId {\n        *self\n            .application_creator_chain_id\n            .get_or_insert_with(|| base_wit::get_application_creator_chain_id().into())\n    }\n","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-sdk/src/contract/runtime.rs#L65-L101","documentation":"ContractRuntime::application_parameters (linera-sdk/src/contract/runtime.rs:78) lazily fetches the creation-time parameter bytes from the host and deserializes them with serde_json into Application::Parameters, expecting success. The panic fires when those bytes were produced from a different Parameters type than the contract declares - field renames, missing fields, or wrong JSON types. Because this runs inside contract execution, a mismatch fails the whole operation.","triggerScenarios":"The application was created with --json-parameters (or programmatically serialized parameters) whose JSON does not match the contract's Parameters type: renamed/missing fields, wrong types, or parameters built by an older version of the application's shared crate.","commonSituations":"Passing hand-written JSON parameters at publish time that drift from the struct; upgrading the application's Parameters type without recreating the application; frontend and contract using different shared-crate versions.","solutions":["Define Parameters once in the application's shared crate and serialize creation parameters from that same type.","Validate the JSON against the contract's Parameters before creating the application (serde round-trip in a test).","If Parameters changed, publish and create a new application instance rather than reusing the old one.","Check field naming (serde rename attributes) between the JSON and the struct."],"exampleFix":"// before: hand-written JSON at creation\n// linera publish-application ... --json-parameters '{\"fee\": 5}'\n// contract expects: struct Parameters { fee_percent: u64 }\n\n// after: derive JSON from the shared type\nlet params = my_app::Parameters { fee_percent: 5 };\nlet json = serde_json::to_string(&params)?; // guaranteed to match the contract's type","handlingStrategy":"validation","validationCode":"// At application-creation time, build parameters from the same type the contract uses:\nuse my_app_abi::Parameters;\nlet json = serde_json::to_string(&parameters)?;\n// off-chain round-trip proves the contract's deserialization will succeed\nserde_json::from_str::<Parameters>(&json)?;","typeGuard":"fn parameters_round_trip(p: &Parameters) -> bool {\n    serde_json::to_string(p).ok().and_then(|s| serde_json::from_str::<Parameters>(&s).ok()).is_some()\n}","tryCatchPattern":"// The expect runs inside the contract runtime; there is no catch on the caller side.\n// Validate the JSON against the contract's Parameters before creating the application,\n// and never change the Parameters type of a live application.","preventionTips":["Define Parameters once in the shared crate and serialize creation arguments from it.","Do not hand-edit --json-parameters strings; generate them with a small script or CLI built on the shared crate.","After changing Parameters, publish and instantiate a new application rather than mutating the old one.","Include a serde round-trip unit test for Parameters in the application's test suite."],"tags":["linera-sdk","contract","serde","json","parameters","deserialization","panic","rust"],"backgroundTag":"json-deserialization-mismatch","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}