Incorrect error message for maxCount exceeded.
- Dominant language
- JavaScript
- Stars
- 12.1k
- Forks
- 1.1k
- Avg merge
- 8d 2h
- Merged PRs (30d)
- 21
Description
Currently, when the number of files a user is uploading is greater than the `maxCount`, the system responds with a `"MulterError: Unexpected field"` message. It should respond with `"MulterError: Too many files"`.
[See code here](https://github.com/expressjs/multer/blob/6b5fff5feaf740f249b1b2858e5d06009cbd245c/index.js#L38-L41)
```
function wrappedFileFilter (req, file, cb) {
if ((filesLeft[file.fieldname] || 0) <= 0) {
return cb(new MulterError('LIMIT_UNEXPECTED_FILE', file.fieldname))
}
filesLeft[file.fieldname] -= 1
fileFilter(req, file, cb)
}
```
Suggested edit:
```
function wrappedFileFilter (req, file, cb) {
if ((filesLeft[file.fieldname] || 0) <= 0) {
return cb(new MulterError('LIMIT_FILE_COUNT', file.fieldname))
}
filesLeft[file.fieldname] -= 1
fileFilter(req, file, cb)
}
```
Contributor guide
Research direction
Start in index.js at the linked wrappedFileFilter code and inspect how MulterError codes are mapped to messages. Confirm the maxCount path produces the intended error, then run the relevant existing test suite or error-handling tests if available. Done means exceeding maxCount reports "MulterError: Too many files" rather than "Unexpected field".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100