googleapis / googleapis/google-cloud-python

Replace `except:` and `except Exception:` with a more granular exception

未關閉
#16,201 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
priority: p2 type: process
主要語言
Python
星號
5.4k
分支
1.8k
平均合併
2 天 23 小時
30 天內合併 PR
123

描述

See feedback from gemini in PR https://github.com/googleapis/gapic-generator-python/pull/2549:

https://github.com/googleapis/gapic-generator-python/pull/2549#discussion_r2747934082

```
The except: on the next line is a bare except, which is a bad practice as it catches all exceptions, including system-exiting ones like SystemExit and KeyboardInterrupt. This can make debugging difficult and hide underlying issues. It would be better to catch a more specific exception, like Exception.

While there's a TODO in the template to remove this try/except block, improving it in the meantime would be beneficial.

This change should be applied to the template file: gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2.

Suggested change in the template:

except Exception:
```

We should remove all usages of `except:` and replace them with `except Exception:` or a more granular exception

Search results for `except:`

https://github.com/search?q=repo%3Agoogleapis%2Fgapic-generator-python%20except%3A&type=code

Search results for `except Exception:`
https://github.com/search?q=repo%3Agoogleapis%2Fgapic-generator-python+%22except+Exception%3A%22&type=code

貢獻指南

開啟貢獻指南

研究方向

從 gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2 開始,並使用連結的搜尋結果定位 repository 中所有裸 except 子句。將每個子句替換為 Exception,或在有充分理由時替換為更具體的例外,然後確認沒有殘留任何非預期的裸 except 用法。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
devtools
Issue 類型
重構
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
64/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。