fix: _AllowedSurfaceIDs.__call__ silently returning None on malformed surface info#5049
fix: _AllowedSurfaceIDs.__call__ silently returning None on malformed surface info#5049Copilot wants to merge 6 commits into
Conversation
Up to standards ✅🟢 Issues
|
…ndexError Agent-Logs-Url: https://github.com/ansys/pyfluent/sessions/068476b6-21c5-4c0a-a683-3096b157ad4f Co-authored-by: Gobot1234 <50501825+Gobot1234@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves error reporting in the field data surface-ID lookup path by ensuring malformed surface metadata triggers a descriptive exception at the source, rather than returning None and failing later with an unrelated TypeError.
Changes:
- Updated
_AllowedSurfaceIDs.__call__to iterate per-surface and raise a descriptiveLookupErroron missingsurface_idor emptysurface_idlist. - Added unit tests covering both malformed-surface-info cases and verifying
_SurfaceIds.validatepropagates theLookupError.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/ansys/fluent/core/field_data_interfaces.py |
Replace silent exception swallow/implicit None return with explicit per-surface LookupErrors containing the surface name and failure mode. |
tests/test_field_data.py |
Add regression tests for missing surface_id key, empty surface_id list, and propagation through _SurfaceIds.validate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| surface_ids = [] | ||
| for surface_name, info in surface_info.items(): | ||
| try: | ||
| surface_ids.append(info["surface_id"][0]) |
There was a problem hiding this comment.
If a user faces the below KeyError and IndexError, they will not know how to fix that error by reading the error-message. The key and the index are hardcoded values in the code, those are not supplied by the user.
Is there a real scenario where these errors can happen due to some user error? If the errors are due to some implementation logic (either in server or client), then that should be handled in the code without raising user-facing errors.
There was a problem hiding this comment.
No I don't think there are I'm pretty sure you'd only hit this in an implementation failure. How would you handle this in the code in this case?
There was a problem hiding this comment.
If we can ignore the missing key/index, we can simply return an empty list.
If we cannot ignore the missing key/index, that means an implementation issue. In that case we can do a debug-log for now and return an empty list. Ideally, the implementation should be fixed.
@prmukherj Please guide which of the above scenarios is the case here.
_AllowedSurfaceIDs.__call__silently swallowedKeyError/IndexErrorand returnedNone, causing a confusing downstreamTypeError: argument of type 'NoneType' is not iterablein_SurfaceIds.validate.Context
When a surface entry in
_get_surfaces_info()is missing thesurface_idkey or has an emptysurface_idlist, the method caught both exceptions and fell off the end, returningNone. Callers like_SurfaceIds.validatethen failed with aTypeErrorthat gave no indication of the actual root cause.Change Summary
_AllowedSurfaceIDs.__call__: replaced the silent catch-all with a per-surface loop that raises a descriptiveLookupErrornaming the offending surface and whether the failure was a missing key or empty index:KeyErrorpath, theIndexError(empty list) path, and propagation through_SurfaceIds.validate.Rationale
Raising a
LookupErrorwith the surface name pinpoints the bad data immediately, rather than silently producingNoneand letting an unrelatedTypeErrorsurface elsewhere.Impact
_AllowedSurfaceIDs.__call__and any callers that previously receivedNone(e.g.,_SurfaceIds.validate,_get_surface_ids) will now get a clearLookupErrorinstead of a silentNoneor a misleadingTypeError.