AOSSIE-Org / AOSSIE-Org/PictoPy
YOLO and ObjectClassifier fail silently on invalid or unreadable images
- Lingua principale
- Python
- Stelle
- 283
- Fork
- 679
- Merge medio
- 7g 2h
- PR unite (30g)
- 3
Descrizione
### Is there an existing issue for this?
- [x] I have searched the existing issues
### What happened?
## Bug Description
The YOLO and ObjectClassifier modules fail silently when an invalid or unreadable image file is provided.
When `cv2.imread()` returns `None`, the models previously returned empty results instead of raising a clear error.
This leads to confusing API behavior and makes debugging difficult.
---
## Expected Behavior
When an invalid or unreadable image is provided:
- The API should return a structured **400 Bad Request** error.
- The frontend should receive a meaningful error message.
- Backend logs should clearly record the failure.
- Internal detection resources should be safely released.
---
## Current Behavior
- `cv2.imread()` returns `None`
- No proper exception was raised earlier
- API returned empty results instead of an error
- Frontend receives misleading "no detections"
- Debugging becomes difficult
---
## Proposed Fix
- Raise `HTTPException(status_code=400)` when the image is invalid/unreadable.
- Sanitize error messages to avoid exposing server file paths.
- Add consistent validation logic across YOLO and ObjectClassifier.
- Add unit tests to verify correct error handling.
---
## Related Pull Request
Fix implemented in PR:
Fix: Standardize invalid image handling in YOLO and ObjectClassifier #679
---
## Testing
- Valid image → YOLO and ObjectClassifier behave normally
- Corrupted image → API returns 400 Bad Request
- Missing file → Proper HTTPException raised
---
## Labels
bug, backend, validation, tests, good first issue
### Record
- [x] I agree to follow this project's Code of Conduct
### Checklist before Submitting
- [ ] Have you updated docs for it?
- [ ] Have you added unit tests?
- [ ] Have you made sure unit tests pass?
- [x] Have you made sure code formatting is correct?
- [ ] Do Your changes passes all tests?
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.