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

Improve TOML placeholder parser error messages

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

还没有人认领这个 Issue。

评估

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

调研方向

Start in hexdoc/utils/deserialize/toml.py, where the traceback shows placeholder expansion reaches _expand_placeholder and raises IndexError. Read the placeholder parsing and expansion flow, then check for related tests in the repository. Done means invalid placeholder references produce a clear parser error instead of this raw index error; no test file is named in the issue.

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

描述

bug

For example, when a placeholder key contains too many parent references, this is the current error message:

─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ E:\Projects\Complex-Hex\.venv\Lib\site-packages\hexdoc\cli\app.py:186 in build                   │
│                                                                                                  │
│   183 │   For developers: returns the site path (eg. `/v/latest/main`).                          │
│   184 │   """                                                                                    │
│   185 │                                                                                          │
│ ❱ 186 │   props, pm, book_plugin, plugin = load_common_data(props_file, branch)                  │
│   187 │                                                                                          │
│   188 │   if props.env.hexdoc_subdirectory:                                                      │
│   189 │   │   output_dir /= props.env.hexdoc_subdirectory                                        │
│                                                                                                  │
│ E:\Projects\Complex-Hex\.venv\Lib\site-packages\hexdoc\cli\utils\load.py:55 in load_common_data  │
│                                                                                                  │
│    52 │   *,                                                                                     │
│    53 │   book: bool = False,                                                                    │
│    54 ) -> tuple[Properties, PluginManager, BookPlugin[Any], ModPlugin]:                         │
│ ❱  55 │   props = Properties.load(props_file)                                                    │
│    56 │   pm = PluginManager(branch, props)                                                      │
│    57 │                                                                                          │
│    58 │   book_plugin = pm.book_plugin(props.book_type)                                          │
│                                                                                                  │
│ E:\Projects\Complex-Hex\.venv\Lib\site-packages\hexdoc\core\properties.py:175 in load            │
│                                                                                                  │
│   172 │   def load(cls, path: Path) -> Self:                                                     │
│   173 │   │   return cls.load_data(                                                              │
│   174 │   │   │   props_dir=path.parent,                                                         │
│ ❱ 175 │   │   │   data=load_toml_with_placeholders(path),                                        │
│   176 │   │   )                                                                                  │
│   177 │                                                                                          │
│   178 │   @classmethod                                                                           │
│                                                                                                  │
│ E:\Projects\Complex-Hex\.venv\Lib\site-packages\hexdoc\utils\deserialize\toml.py:135 in          │
│ load_toml_with_placeholders                                                                      │
│                                                                                                  │
│   132                                                                                            │
│   133 def load_toml_with_placeholders(path: Path) -> TOMLDict:                                   │
│   134 │   data = tomllib.loads(path.read_text("utf-8"))                                          │
│ ❱ 135 │   fill_placeholders(data)                                                                │
│   136 │   return data                                                                            │
│   137                                                                                            │
│   138                                                                                            │
│                                                                                                  │
│ E:\Projects\Complex-Hex\.venv\Lib\site-packages\hexdoc\utils\deserialize\toml.py:34 in           │
│ fill_placeholders                                                                                │
│                                                                                                  │
│    31                                                                                            │
│    32                                                                                            │
│    33 def fill_placeholders(data: TOMLDict):                                                     │
│ ❱  34 │   _fill_placeholders(data, [data], set())                                                │
│    35                                                                                            │
│    36                                                                                            │
│    37 def _expand_placeholder(                                                                   │
│                                                                                                  │
│ E:\Projects\Complex-Hex\.venv\Lib\site-packages\hexdoc\utils\deserialize\toml.py:130 in          │
│ _fill_placeholders                                                                               │
│                                                                                                  │
│   127 ):                                                                                         │
│   128 │   table = stack[-1]                                                                      │
│   129 │   for key, child in table.items():                                                       │
│ ❱ 130 │   │   _handle_child(data, stack, expanded, key, child, table.__setitem__)                │
│   131                                                                                            │
│   132                                                                                            │
│   133 def load_toml_with_placeholders(path: Path) -> TOMLDict:                                   │
│                                                                                                  │
│ E:\Projects\Complex-Hex\.venv\Lib\site-packages\hexdoc\utils\deserialize\toml.py:113 in          │
│ _handle_child                                                                                    │
│                                                                                                  │
│   110 │   │   case list():                                                                       │
│   111 │   │   │   # handle each item in the list without adding the list to the stack            │
│   112 │   │   │   for i, item in enumerate(value):                                               │
│ ❱ 113 │   │   │   │   _handle_child(data, stack, expanded, i, item, value.__setitem__)           │
│   114 │   │                                                                                      │
│   115 │   │   case dict():                                                                       │
│   116 │   │   │   # recursion!                                                                   │
│                                                                                                  │
│ E:\Projects\Complex-Hex\.venv\Lib\site-packages\hexdoc\utils\deserialize\toml.py:89 in           │
│ _handle_child                                                                                    │
│                                                                                                  │
│    86 │   │   │   # fill the string's placeholders                                               │
│    87 │   │   │   for match in reversed(list(_PLACEHOLDER_RE.finditer(value))):                  │
│    88 │   │   │   │   try:                                                                       │
│ ❱  89 │   │   │   │   │   v = _expand_placeholder(                                               │
│    90 │   │   │   │   │   │   data,                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
IndexError: list index out of range
主要语言
Python
星标
7
派生
10
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

hexdoc-dev/hexdoc 的其他 Issue

查看 hexdoc-dev/hexdoc 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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