{"record":{"id":"004b597fb679cefd","repo":"seanmonstar/warp","slug":"checked-for-name-previously","errorCode":null,"errorMessage":"checked for name previously","messagePattern":"checked for name previously","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/filters/multipart.rs","lineNumber":143,"sourceCode":"                    Poll::Ready(Some(Ok(Part { part })))\n                } else {\n                    Poll::Ready(Some(Err(crate::Error::new(MultipartFieldMissingName))))\n                }\n            }\n            Poll::Ready(Ok(None)) => Poll::Ready(None),\n            Poll::Ready(Err(err)) => Poll::Ready(Some(Err(crate::Error::new(err)))),\n        }\n    }\n}\n\n// ===== impl Part =====\n\nimpl Part {\n    /// Get the name of this part.\n    pub fn name(&self) -> &str {\n        self.part\n            .name()\n            .unwrap_or_else(|| self.part.file_name().expect(\"checked for name previously\"))\n    }\n\n    /// Get the filename of this part, if present.\n    pub fn filename(&self) -> Option<&str> {\n        self.part.file_name()\n    }\n\n    /// Get the content-type of this part, if present.\n    pub fn content_type(&self) -> Option<&str> {\n        let content_type = self.part.content_type();\n        content_type.map(|t| t.as_ref())\n    }\n\n    /// Asynchronously get some of the data for this `Part`.\n    pub async fn data(&mut self) -> Option<Result<impl Buf, crate::Error>> {\n        future::poll_fn(|cx| self.poll_next(cx)).await\n    }\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/seanmonstar/warp/blob/ff34d7213ed55ec342304aa7ff6ac4b351da9e66/src/filters/multipart.rs#L125-L161","documentation":"`warp::multipart::Part::name()` returns the part's form field name, falling back to `file_name().expect(\"checked for name previously\")` (src/filters/multipart.rs:143). The expect assumes that whenever `name()` is absent, `file_name()` is present — an invariant from the underlying multipart parsing. If the invariant breaks (a part has neither a name nor a filename), this panics with an internal-invariant message rather than returning a value.","triggerScenarios":"Calling `part.name()` on a multipart part whose underlying `Part` has neither a `name` disposition param nor a `filename` param — e.g. hand-crafted or malformed multipart bodies where the Content-Disposition lacks both.","commonSituations":"Proxies or clients sending multipart bodies with `Content-Disposition: form-data` and no name/filename; fuzzed or malformed uploads; older/odd clients that omit the name attribute on file fields.","solutions":["Prefer `part.filename()` or the underlying optional accessors when you cannot guarantee the part has a name","Validate Content-Disposition on the client side so every form field includes a name attribute","If hit in practice, treat the request as malformed and reject it before touching `name()`","Guard in your handler: check filename() first, then fall back to a synthetic name instead of calling name() blindly"],"exampleFix":"// before\nlet field_name = part.name().to_string();\n// after\nlet field_name = part.filename()\n    .map(|f| f.to_string())\n    .unwrap_or_else(|| \"unnamed-part\".to_string());","handlingStrategy":"fallback","validationCode":"// check before relying on name():\nlet label = part.filename().map(str::to_owned).unwrap_or_else(|| \"<unnamed>\".into());","typeGuard":null,"tryCatchPattern":"// cannot catch a panic in sync code here; avoid by using optional accessors:\nlet name = part.filename().map(|f| f.to_string())\n    .unwrap_or_else(|| format!(\"part-{}\", index));","preventionTips":["Treat multipart parts as optionally-named; don't assume name() always succeeds","Reject malformed multipart requests early in the filter chain","Test with hand-crafted Content-Disposition headers lacking name/filename","Prefer filename() or the underlying library's optional getters in generic handlers"],"tags":["multipart","panic","internal-invariant","http"],"backgroundTag":"internal-invariant-violation","analyzedSha":"ff34d7213ed55ec342304aa7ff6ac4b351da9e66","analyzedAt":"2026-09-09T16:57:46.316Z","contentChangedAt":"2026-09-09T16:57:46.316Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}