Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Maybe flatten out exception tree

未关闭
#41 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

首先审查当前的异常层次结构以及拟议的 exceptions.general、exceptions.http、exceptions.opening、exceptions.kv_store 和 exceptions.acl 模块。然后检查生成器及其冲突处理机制。完成的标准是:就层次结构和名称达成一致,在不意外改变父级关系的情况下实现扁平化,并添加冲突防护。

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

描述

This is a ticket for discussion and design, responding to Paul's comment about nested exceptions being awkward to reach for.

--

I spread all the errors out on the table and had a look. We can get a pretty nice result by dividing exceptions across 5 modules, while still saving ourselves from utterly changing the shape of the world (fighting the WIT forevermore). No more subpackages under exceptions, just 5 files:

  • exceptions.general:

    • All from types.error. I don't see a point in having a common superclass for these at all; there's no semantic, and it doesn't really help catchers narrow down what threw it, as many things throw these.
    • Move HttpInvalid, HttpUser, and HttpIncomplete to exceptions.http, though.
    • It's unfortunate GenericError exists, as it sound a lot like UnexpectedFastlyError. UnexpectedFastlyError should become private, as it indicates a bug in our code if it's thrown. People definitely shouldn't be catching it. Catch Exception or FastlyException if you want a catch-all.
    • Rename GenericError to OtherError to get a little closer to its meaning. "Generic" suggests to me a superset of the other errors, while "Other" unambiguously indicates it's not one of those errors.
  • exceptions.http:

    • ErrorWithDetail with a better name, like HttpError.
    • All the send-error-detail exceptions error-with-detail carries (not currently generated). Map any ErrorWithDetail that has (optional) details directly onto these, subclassing HttpError.
    • All the trailer-errors. Rename Error to OtherError.
  • exceptions.opening:

    • All open-error errors. This is actually a pretty semantically cohesive category.
  • exceptions.kv_store:

    • All kv-error errors.
    • There's another GenericError there. Rename it to OtherError.
  • exceptions.acl:

    • All the acl-errors. Rename GenericError to OtherError.

Open questions

  • Are we going to cause trouble for ourselves by changing the parentage of some errors, like making error's HttpInvalid superclass exceptions.http.HttpError (or perhaps some other common ancestor)? I rather think so. The common-ancestor approach sounds good. The error superclass is worthless, but the error-with-detail one may have meaning.

Name collisions (if we were to flatten everything into 1 module):

  • Error (x2), but we can probably remove the types.error.Error common superclass to make that go away.
  • GenericError (x4)
  • LimitExceeded (x2)
  • TooManyRequests (x2)
  • Unsupported (x2)

Paths not taken

We could deduplicate and have, say, ACL stuff and non-ACL stuff throw the same TooManyRequests error, but we'd be losing potentially important info for the catcher. So that's a bad idea. (Also, it could get messy if the 2 TooManyRequests errors later diverge in shape, which might happen if WIT grows subtyping.)

Thus, we must rename exceptions or divide up into modules.

If we flatten and rename, we get into trouble in the future when somebody introduces another InternalError and we never prefixed the KV one into KvStoreInternalError. I'm against preemptively prefixing the heck out of everything, because it gets wordy and this isn't Java. And does one really need to say HttpTrailerError? There are unlikely to be other kinds of trailer errors. But if we don't prefix universally, it becomes awkward to program against because you constantly have to look aside to see what we named things. So let's keep the names short and just make a better __repr__ instead if needed to clarify tracebacks.

Prerequisites

We'd need to add alarm bells about collisions in the generator so we don't accidentally template duplicate names into one module.

主要语言
Python
星标
5
派生
1
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fastly/compute-sdk-python 的其他 Issue

查看 fastly/compute-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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