Skip to content

Skip members that raise when listing them for help - #699

Open
rootkiller6788 wants to merge 2 commits into
google:masterfrom
rootkiller6788:fix-help-raised-property
Open

Skip members that raise when listing them for help#699
rootkiller6788 wants to merge 2 commits into
google:masterfrom
rootkiller6788:fix-help-raised-property

Conversation

@rootkiller6788

Copy link
Copy Markdown

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 -- --help and the --help shortcut now print help listing the working methods, exit code 0. Added a regression test covering those three paths.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught exception when a component has a property whose getter raises (intended?)

1 participant