googleapis / googleapis/google-cloud-python
Replace `except:` and `except Exception:` with a more granular exception
- Linguagem predominante
- Python
- Estrelas
- 5.4k
- Forks
- 1.8k
- Merge médio
- 2d 23h
- PRs com merge (30d)
- 123
Descrição
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
Guia de contribuição
Direção de pesquisa
Comece com gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2 e use os resultados de pesquisa vinculados para localizar todas as cláusulas except simples no repositório. Substitua cada uma por Exception ou por uma exceção mais específica quando houver justificativa; em seguida, verifique se não restaram usos não intencionais de except simples.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- devtools
- Tipo de issue
- Refatoração
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Pouca atividade
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 64/100