google / google/python-fire

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

未关闭
#672 5 条评论 0 个 reaction 已指派 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.

贡献指南

打开贡献指南

调研方向

从提供的 app.py 复现程序开始,跟踪无参数调用和 --help 使用的成员枚举路径。将该路径与直接调用 greet 进行比较,然后为会引发异常的属性添加覆盖;完成的标准是,help 和无参数调用按照选定的行为处理 getter 失败,同时 greet 仍能正常工作。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
cli
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
58/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。