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 摘要。