AOSSIE-Org / AOSSIE-Org/PictoPy

FaceDetector fails silently when invalid or unreadable images are provided

Aperta
#709 5 commenti 0 reazioni 1 assegnatario Rivendicata da @arpittkhandelwal Vedi su GitHub
backend bug
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 FaceDetector module currently fails silently when an invalid or unreadable image file is provided.
Specifically, `cv2.imread()` returns `None`, and the function proceeds without raising a proper error.
This causes unexpected behavior in the backend and frontend without informing the API consumer.

---

## Expected Behavior
When an invalid or unreadable image is uploaded:
- The API should return a clear and structured **400 Bad Request** error.
- The frontend should receive a meaningful error message instead of a silent failure.
- Backend logs should clearly show the failure reason.

---

## Current Behavior
- `cv2.imread()` returns `None`
- No exception is raised
- The API returns `None`
- Frontend receives no proper error feedback
- Debugging becomes difficult

---

## Proposed Fix
- Raise `HTTPException(status_code=400)` when the image is invalid/unreadable.
- Add proper error logging.
- Ensure internal detector resources are safely closed after failure.

---

## Related Pull Request
Fix implemented in PR:
Properly handle invalid or unreadable images in FaceDetector #677

---

## Testing
- Valid images → face detection works correctly
- Corrupted image → API returns 400 error
- Missing file → Proper exception raised

---

## Labels
bug, backend, validation, 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.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.