{"record":{"id":"f12ca650c7f3c3b8","repo":"juspay/hyperswitch","slug":"webhook-event-type-should-be-derived","errorCode":null,"errorMessage":"webhook event type should be derived","messagePattern":"webhook event type should be derived","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/hyperswitch_connectors/src/connectors/gocardless.rs","lineNumber":990,"sourceCode":"            }]\n        })\n        .to_string()\n        .into_bytes()\n    }\n\n    fn event_type_for(resource_type: &str, action: &str, link_key: &str) -> IncomingWebhookEvent {\n        let body = webhook_body(resource_type, action, link_key);\n        let headers = actix_web::http::header::HeaderMap::new();\n        let request = IncomingWebhookRequestDetails {\n            method: http::Method::POST,\n            uri: http::Uri::from_static(\"/webhooks\"),\n            headers: &headers,\n            body: &body,\n            query_params: String::new(),\n        };\n        Gocardless::new()\n            .get_webhook_event_type(&request, None)\n            .expect(\"webhook event type should be derived\")\n    }\n\n    #[test]\n    fn refund_actions_shared_with_payments_map_to_refund_events() {\n        assert_eq!(\n            event_type_for(\"refunds\", \"failed\", \"refund\"),\n            IncomingWebhookEvent::RefundFailure\n        );\n        assert_eq!(\n            event_type_for(\"refunds\", \"created\", \"refund\"),\n            IncomingWebhookEvent::EventNotSupported\n        );\n        assert_eq!(\n            event_type_for(\"refunds\", \"paid\", \"refund\"),\n            IncomingWebhookEvent::RefundSuccess\n        );\n    }\n","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/juspay/hyperswitch/blob/afd92843521ced2c6856b98ae4ea332e75102d88/crates/hyperswitch_connectors/src/connectors/gocardless.rs#L972-L1008","documentation":"Test helper `event_type_for` in gocardless.rs calls `get_webhook_event_type(...).expect(\"webhook event type should be derived\")`. The panic means Gocardless webhook parsing failed to derive an event type from the constructed request (body/action parsing returned Err).","triggerScenarios":"A GoCardless webhook body whose `action`/resource type is not handled (or malformed JSON) is passed to get_webhook_event_type, which returns Err and the expect panics.","commonSituations":"Adding a new GoCardless event action to tests before extending the connector's event-type mapping, or a body fixture that does not match the expected serde schema.","solutions":["Extend the connector's event-type mapping to cover the new GoCardless action/resource type","Verify the test body fixture deserializes into the expected GoCardless webhook payload struct","Change expect to a match on Err to surface the parse error message"],"exampleFix":"// before\n.expect(\"webhook event type should be derived\")\n// after\n.unwrap_or_else(|e| panic!(\"webhook event type should be derived: {e:?}\"))","handlingStrategy":"try-catch","validationCode":"let payload: GocardlessIncomingWebhook = serde_json::from_str(body).expect(\"fixture must deserialize\");","typeGuard":"fn event_resolvable(body: &str) -> bool {\n    serde_json::from_str::<GocardlessWebhookBody>(body).map(|p| p.action_type().is_some()).unwrap_or(false)\n}","tryCatchPattern":"get_webhook_event_type(&request, None).unwrap_or_else(|e| panic!(\"webhook event type should be derived: {e:?}\"))","preventionTips":["Extend the action->event-type map when adding GoCardless events","Validate fixtures deserialize before asserting"],"tags":["rust","tests","webhooks","gocardless"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"afd92843521ced2c6856b98ae4ea332e75102d88","analyzedAt":"2026-09-18T01:18:02.947Z","contentChangedAt":"2026-09-18T01:18:02.947Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}