Skip members that raise when listing them for help - #699
Open
rootkiller6788 wants to merge 2 commits into
Open
Conversation
Enumerating a component's members for help or completion runs each member's getter, including property getters. A getter that raises anything other than AttributeError currently makes inspect.getmembers abort, so running a CLI with no args or with --help crashes with the property's raw traceback instead of showing usage. Add inspectutils.GetMembers, which keeps the normal getmembers path but falls back to reading members one at a time and skipping the ones that raise, and use it where members are enumerated for help.
A component with a property whose getter raises used to crash Fire when it tried to show help or list the component. The test covers bare invocation, the --help flag, and the --help shortcut.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #672.
If a component has a property whose getter raises (say a lazy config that hits a backend), then running the CLI with no args or with --help crashed with the property's raw traceback, because Fire enumerates every member -- and reads property values -- while building help. inspect.getmembers aborts on any exception that isn't AttributeError, so one bad property took down the whole help screen even though it was never called.
This adds a GetMembers helper in inspectutils that keeps the normal inspect.getmembers path, but if that raises it falls back to reading members one at a time and skipping the ones that fail. Help and completion only need the members that can actually be read, so a broken property is left out of the listing instead of killing the command. VisibleMembers and the --help shortcut handling in core.py now go through this helper.
Verified locally: with a class whose property getter raises RuntimeError, bare invocation and both
-- --helpand the--helpshortcut now print help listing the working methods, exit code 0. Added a regression test covering those three paths.