AOSSIE-Org / AOSSIE-Org/PictoPy

YOLO and ObjectClassifier fail silently on invalid or unreadable images

Abierto
#710 0 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 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?

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.