AOSSIE-Org / AOSSIE-Org/PictoPy

YOLO and ObjectClassifier fail silently on invalid or unreadable images

未關閉
#710 0 則留言 0 個 reaction 已指派 1 人 已被 @arpittkhandelwal 認領 在 GitHub 檢視
backend bug
主要語言
Python
星號
283
分支
679
平均合併
7 天 2 小時
30 天內合併 PR
3

描述

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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。