is this a good or bad code review suggestion?: code: except Exception as e:…
- User
is this a good or bad code review suggestion?:
code: except Exception as e: self.logger.exception('Failed during ._analyse_pdf()') raise HTTPException(status_code=422, detail=f'Failed during ._analyse_pdf(): {e}')
suggestion: Extractor nie musi być wywołany przez API. Lepiej rzucić jakiś inny exception i wyłapać go wyżej
- Assistant
The suggestion is good in its intent, but it could be more detailed and precise. Here’s a breakdown:
-
Intent (Separation of Concerns):
The comment points out that the extractor (a lower-level component) shouldn’t be aware of HTTP-level exceptions. It’s advocating for better separation of concerns—i.e., letting the error propagate as a domain‐ or custom exception and then mapping that to an HTTP response at the API layer. This is a sound design principle. -
Risk of Coupling:
By raising anHTTPExceptiondirectly in a possibly lower-level component, you tightly couple that part of your codebase to the web/API framework (for example, FastAPI). This reduces the ability to reuse the component in other contexts (e.g., a CLI tool, background worker, etc.). The suggestion correctly identifies this issue. -
Improvements Needed:
- Clarity on the Alternative: The suggestion says to "raise some other exception" and catch it higher, but it doesn’t specify what exception. A more constructive suggestion might name a specific custom exception (e.g.,
PDFAnalyseError) or recommend creating one. - Context of Handling: It would be beneficial to outline where and how the new exception should be caught to convert it into an HTTP response, ensuring that responsibilities remain clearly separated.
- Clarity on the Alternative: The suggestion says to "raise some other exception" and catch it higher, but it doesn’t specify what exception. A more constructive suggestion might name a specific custom exception (e.g.,
Summary:
Overall, the review suggestion is good because it highlights an important architectural concern—avoid tying lower-level logic to specific frameworks like FastAPI. However, it could be improved by offering more concrete guidance on what type of exception to raise and how to handle it at a higher or interface layer. -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.