AOSSIE-Org / AOSSIE-Org/PictoPy

FaceDetector fails silently when invalid or unreadable images are provided

Abierto
#709 5 comentarios 0 reacciones 1 asignado Reclamado por @arpittkhandelwal Ver en GitHub
backend bug
Lenguaje dominante
Python
Estrellas
283
Forks
679
Merge medio
7 d 2 h
PR fusionados (30 d)
3

Descripción

### 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?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.