google / google/python-fire

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

オープン
#672 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
28.2k
フォーク
1.5k
PR マージ指標
30日以内にマージされた PR はありません

説明

When a component has a `@property` whose getter raises, `fire.Fire(component)` crashes with the property's raw traceback on bare invocation and on `--help`, instead of showing usage/help. A direct call to an unrelated method works fine.

Repro (fire 0.7.1):

```python
import fire

class App:
@property
def status(self):
raise RuntimeError("backend unavailable") # e.g. a lazy / fallible getter

def greet(self, who="world"):
return f"hi {who}"

if __name__ == "__main__":
fire.Fire(App())
```

```
$ python app.py --help
...
value = getter(object, key)
File "app.py", line 5, in status
raise RuntimeError("backend unavailable")
RuntimeError: backend unavailable

$ python app.py greet # works
hi world
```

Fire enumerates members (and reads property *values*) during help/listing, so any property getter that can raise (lazy config, DB or network access, etc.) takes down `--help` and bare invocation, even though those properties are never invoked.

Is this intended, or should Fire surface a clean error (or skip properties that raise) during member enumeration? Happy to send a PR if a fix would be welcome.

Found via automated analysis and confirmed with the reproducer above on fire 0.7.1.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。