Skip to content

fix(diagnostics): report pdfTeX and fatal engine errors - #68

Merged
nishide-dev merged 5 commits into
mainfrom
fix/pdftex-errors
Oct 6, 2026
Merged

nishide-dev merged 5 commits into
mainfrom
fix/pdftex-errors

Conversation

@nishide-dev

@nishide-dev nishide-dev commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

概要

pdfTeX が自分で出す致命的エラー(!pdfTeX error: ...。font や画像を読めないときなど)を log parser が拾わず、outcome: failed なのに diagnostics: [] になっていた問題を直す。あわせて、失敗した compile には必ず error diagnostic が 1 件以上付くようにする。

変更内容

  • texrun-latex-log
    • !pdfTeX error: ...(! の後に空白がなく、-file-line-error でも file:line: にならず、l.<n> もない)を error / other として報告する。直後の空白始まりの ==> Fatal error occurred, ... は、TeX エラー後の stop と同じく emergency_stop の info として扱う(feat(diagnostics): locate missing packages and fold fatal errors #40 の方針どおり、error の数が直すべき問題の数)
    • pdfTeX は位置を出さず、font のように input を読み終えて PDF を書く段階で落ちることも多いので、file / line は常に None(file stack の推測もしない。message に font 名や画像名が入る)
    • unexplained_failure(log) を公開:失敗したのに error が見つからないとき用に、log 末尾(最後の 16 KiB のうち非空行を最大 12 行)を raw_excerpt に持つ error / other を返す。末尾に ! 行があればそれを message に引用する。計算量は log サイズに依らず定数、message / excerpt は既存と同じ上限と sanitize を通す
  • texrun-texlive:outcome: failed で error diagnostic が 0 件のとき(log・texrun・BibTeX のどれも error を出さなかったとき)だけ、上記の error を追加する。log の読み込みは既存の 1 回分を使い回す
  • kind は新設せず other にした。! pdfTeX error (ext4): ... のように TeX のエラールーチン経由の pdfTeX エラーは従来から other で、同じ pdfTeX 由来のエラーで kind が分かれるのを避けるため。新設は必要になったら後から足せる(未知の kind は other として deserialize される)
  • 実ログ fixture(dev コンテナで生成、regenerate.sh に追加)
    • pdftex-missing-font:T1 の ecrm1000(MKTEXPK=0、TeX Live engine と同じ設定)→ !pdfTeX error: pdflatex (file ecrm1000): Font ecrm1000 at 600 not found(Report pdfTeX errors that the log parser misses #66 の再現)
    • pdftex-missing-image:\pdfximage{nosuch.png} → !pdfTeX error: pdflatex: cannot find image file nosuch.png
    • pdftex-error-ext:\pdfendlink だけ → ./main.tex:5: pdfTeX error (ext4): ...(従来どおり位置付きの other)
    • capacity-exceeded(TeX capacity exceeded)、cannot-write(openout_any=p で I can't write on file)、interruption(SIGINT で Interruption.):いずれも既に file:line: 形式の TeX エラーとして拾えていたことを固定する回帰テスト
  • skill(skills/texrun/SKILL.md、reference/errors.md)を更新
  • docs/cli.md の Diagnostics 節に、pdfTeX エラーの扱いと「失敗時は必ず error がある」ことを追記。crate docs の表も更新

確認方法

  • cargo check --workspace --all-targets --all-features --locked
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test --workspace --all-features --locked(macOS host)
  • dev コンテナで TEXRUN_REQUIRE_TEXLIVE=1 TEXRUN_REQUIRE_PREVIEW_TOOLS=1 cargo test --workspace --all-features --locked
  • dev コンテナで実際に texrun compile して確認:T1 font の文書は error: pdfTeX error: pdflatex (file ecrm1000): Font ecrm1000 at 600 not found(1 error)、\pdfximage の文書は error: pdfTeX error: pdflatex: cannot find image file nosuch.png
  • 追加テスト:実ログ 4 件(real_logs.rs)、pdfTeX エラーが後続の偽 l.<n> や file stack から位置を取らないこと(synthetic.rs)、unexplained_failure の上限・sanitize・! 行の引用(unit)、fake latexmk で「認識できるエラーなら追加しない / 未知形式・log なしなら追加する」(engine.rs)

関連 Issue

Closes #66

補足

  • PR feat(skills): add an Agent Skill for compiling TeX with texrun #64(skill)の merge 後に rebase し、同じ PR で skill を更新:SKILL.md の「failed なのに error がなければ log を読む」という暫定案内を、位置なしの other error(pdfTeX の font / 画像エラー、または log 末尾の抜粋付きの原因不明エラー)の読み方に置き換え、reference/errors.md の other 行に対処を追記。kind は追加していないので skill_docs の整合性テストはそのまま通る。scripts/texrun_summary.py の「error が無い」分岐は古い texrun 向けに残した
  • unexplained_failure は latexmk 自体の失敗(TeX は成功したが latexmk が非 0 で終了など)でも出るが、latexmk の stdout は JSON に出していないので、その場合は TeX log の末尾しか示せない
  • 他の engine(XeTeX / LuaTeX)の ! 直後に空白がない独自形式は未対応だが、その場合も unexplained_failure がその ! 行を message に引用する

🤖 Generated with Claude Code

nishide-dev and others added 4 commits October 7, 2026 07:29
Recognize pdfTeX's own fatal errors (`!pdfTeX error: ...`, e.g. a font
or an image it cannot load) and give every failed compile an error
diagnostic, excerpting the end of the log when no error was recognized.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@nishide-dev nishide-dev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

must-fix / should-fix はありません。#66 の再現(T1 + MKTEXPK=0 の font 不足)がこの PR で 1 error(位置なし other)+ info の stop になること、unexplained_failure が付く条件が outcome: failed かつ error 0 件だけに絞られていて正常終了・timeout・cancel・resource limit では付かないことを、コードと実際の compile の両方で確認しました。#23 の方針(誤った file/line より None)、#40 の方針(stop は error の後なら info)、#42 の方針(計算量・読み込み量に上限)にも沿っています。

ゲート

  • host (macOS): cargo fmt --check / cargo clippy -D warnings / cargo test --workspace --all-features --locked すべて通過
  • dev コンテナ: TEXRUN_REQUIRE_TEXLIVE=1 TEXRUN_REQUIRE_PREVIEW_TOOLS=1 cargo test --workspace --all-features --locked 全件通過(skill_docs も含む)
  • CI はすべて pass

試したケース(dev コンテナ、scratchpad 内、コミットなし)

texrun compile --json での結果:

ケース 結果
T1 fontenc(ecrm1000) error other "pdfTeX error: pdflatex (file ecrm1000): Font ecrm1000 at 600 not found"(file/line なし)+ info stop
\pdfximage{nosuch.png} error other "pdfTeX error: pdflatex: cannot find image file nosuch.png" + info
壊れた PNG を \includegraphics error other "pdfTeX error: pdflatex (file ./bad.png): libpng: internal error" + info(fixture にない形式も拾えている)
壊れた PDF を \includegraphics error other "pdfTeX error: pdflatex (file ./bad.pdf): xpdf: reading PDF image failed" + info
未定義命令の後に T1 font / 存在しない画像 -halt-on-error で先に止まり pdfTeX error は log に出ない。error 1 件 + info、unexplained は付かない
LaTeX Error(itemize/enumerate 不一致) latex_error 1 件 + info
\end{document} なし(! Emergency stop. だけ) error emergency_stop 1 件(従来どおり)、unexplained は付かない
正常終了 / warning のみ succeeded、余計な error なし

parser / unexplained_failure に直接入れた log(実ログの切り詰めと合成):

  • ! LaTeX Error → ==> Fatal error → !pdfTeX error:(no-halt で最終 ship 時に font が落ちる想定): LaTeX error、info stop、pdfTeX error の 2 error。どちらも直すべき別の問題なので件数として正しい。
  • 未定義命令 → !pdfTeX error: → ==> Fatal: 2 error + info 1 件。二重報告なし。
  • !pdfTeX error: の後に ! Emergency stop.: 後者は info(errors_reported が数えられている)。
  • Runaway argument? の直後の !pdfTeX error:、CRLF の log: どちらも正しく拾える。
  • log が途中で切れたもの: !pdfTeX error 行の途中で切れると message も途中まで("pdfTeX error: pdfla")。summary の前で切れると error だけ。! の前で切れると unexplained になり、末尾 12 行が excerpt に入る。いずれも妥当。
  • LuaLaTeX で \directlua{os.exit(3)}(log が途中で終わる): unexplained になり、excerpt は末尾の Font Info 12 行。
  • 計算量: 1 / 64 / 512 MiB の log(80 byte ごとに改行、または改行のない 1 行の !...)で unexplained_failure は 14〜104 µs、message は 2048 B 以下、excerpt は 4096 B 以下。log サイズに依らないことを確認。ESC と不正 UTF-8 は sanitize される(unit test もあり)。
  • この container には XeLaTeX が無いので XeTeX の log は試せていません。LuaTeX の ./x.tex:3: error: (file nosuch.png) (pdf backend): ... は従来どおり file:line: 形式で拾えます。

nit

  1. human 出力で excerpt が見えない: the compile failed, but no error was recognized in the log; its last lines are in the excerpt (see the full log) は、raw_excerpt を表示しない human 出力(human.rs)では見えないものを指しています(その下に log: のパスは出ます)。どちらかで良いと思います。
    • message を出力形式に依らない文にする。例: the compile failed, but no error was recognized in the log; read the end of the log
    • human 出力でこの error に限って raw_excerpt を数行表示する
  2. docs/cli.md の「the last ! line of the log」: 実際に見るのは最後の 16 KiB のうち非空行 12 行だけです。log の前の方の ! 行は引用されません。quotes the last line starting with ! among the last lines of the log のように書くと正確です。
  3. 原因不明の ! 行の後に認識できる stop が続く場合: 合成 log !XeTeX error: odd → ! ==> Fatal error occurred, ... では、stop が error(emergency_stop, "Fatal error occurred...")になります。error が 1 件あるので unexplained は付かず、本当の原因の行はどこにも出ません。texrun の engine は今は pdflatex だけで、pdfTeX 自身の形式はこの PR で拾えるので、今は実害はないと思います。XeTeX / LuaTeX を入れるときの follow-up として、「先に error がない stop しか error がない」場合にも unexplained の excerpt(または stop の excerpt に前の数行)を付けることを検討してください。! Emergency stop. だけのケース(\end{document} なし)で *** (job aborted, no legal \end found) が excerpt に入らないのも同じ種類の既存の弱さです。
  4. errors.md の対処の具体化:
    • Font ecrm1000 at 600 not found には「\usepackage{lmodern} を足す(T1 のまま Type 1 の font にする)か、fontenc の T1 をやめる」と具体的な直し方があると、agent がそのまま直せます。
    • I can't write on file は openout_any=p なので、絶対パスや .. の他に、. で始まる(hidden)ファイルへの書き込みでも出ます。「writing outside the project or to a hidden file」とする方が正確です。
  5. MainLog::new が成功時も unexplained_failure を毎回計算している: 16 KiB の lossy 変換と 12 行の処理だけなので実害はありません。気になるなら、parse_log が log の末尾(最大 16 KiB)だけを持って返し、必要なときだけ計算する形にもできます。
  6. テストの網羅: engine 側のテストは Failed の場合だけです。decide の構造上 timeout / cancel / resource limit では付きませんが、「TimedOut で error 0 件のとき unexplained を足さない」ことを固定するテストが 1 本あると、将来条件を変えたときの回帰を防げます(fake latexmk の sleep + 短い timeout で書けます)。

Word the message so it holds without the excerpt (the human output does
not show it), describe what is quoted precisely, make the skill's fixes
for missing fonts and refused writes concrete, and check that a timeout
gets no extra error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nishide-dev
nishide-dev merged commit afeeb8b into main Oct 6, 2026
11 checks passed
@nishide-dev
nishide-dev deleted the fix/pdftex-errors branch October 6, 2026 22:50
nishide-dev added a commit that referenced this pull request Oct 6, 2026
… image (#67)

## 概要

公開済みの engine image 0.1.0 と dev image では、普通の `itemize` を含む文書が `!pdfTeX
error: pdflatex (file tcrm1000): Font tcrm1000 at 600 not found`
で失敗していた。両 image に Type1
font(`cm-super`・`lmodern`・`texlive-fonts-recommended`)を追加して直す。`MKTEXPK=0`(docs/security.md
§3.4)の方針は変えていない。

## 原因

- LaTeX 2024-11-01(trixie の TeX Live 2024)では、OT1 文書の `\textbullet` が
`\UseTextSymbol{TS1}` になっている(`\?\textbullet` の定義で確認)。そのため `\labelitemi`
を使う `itemize` は TS1 の `tcrm1000` を必要とする。`\usepackage[T1]{fontenc}` の文書も
EC の `ecrm1000` を必要とする
- image には `texlive-latex-base` の
TFM(`fonts/tfm/jknappen/ec/tcrm1000.tfm`)だけが入っていて、Type1(`.pfb` と
map)は入っていなかった
- texrun は `MKTEXPK=0` で bitmap(PK)を生成させないので、pdfTeX は font
を埋め込めずに失敗する。PK を生成させずに Type1 を入れるのが正しい対処
- 再現の結果(修正前)

  | 文書 | engine 0.1.0 | dev image(host backend 相当) |
  | --- | --- | --- |
  | `itemize` だけ | `tcrm1000` not found | 同じ |
| textcomp 記号 +
amsmath/amssymb/graphicx/booktabs/geometry/microtype/hyperref |
`tcrm1000` not found | 同じ |
  | `\usepackage[T1]{fontenc}` + microtype | `ecrm1000` not found | 同じ |
  | T1 + `lmodern` + 上記 | `lmodern.sty` not found | 同じ |
| `mathptmx` / `helvet` / `mathpazo` | `ptmr8t` / `pplr7t` の TFM が無い |
同じ |

- 既存の fixture が通っていた理由: どれも OT1 の本文だけで、`itemize`・textcomp 記号・T1
を使っていなかった。OT1 の Computer Modern の Type1 は `texlive-base`(amsfonts)に入っている

## 変更内容

- `docker/engine/Dockerfile` と `docker/dev/Dockerfile`:
`texlive-fonts-recommended`・`cm-super`・`lmodern`
を追加した(`--no-install-recommends` のまま)。理由はコメントに書いた
- `crates/texrun-texlive/tests/fixtures/common-packages/`: 4 つの文書を追加した
- `main.tex`: 11pt、OT1。入れ子の itemize、enumerate、textcomp 記号(脚注や `\small` /
`\Huge`
の中でも使う)、amsmath/amssymb、graphicx(PNG)、booktabs、geometry、microtype、hyperref
  - `t1.tex`: 12pt、T1。lmodern なしで cm-super をいろいろなサイズで使う
  - `lmodern.tex`: T1 + lmodern + 上記のパッケージ
  - `psnfss.tex`: mathptmx / helvet / courier
  - `palatino.tex`: mathpazo(sc,osf)
  - `main.tex` には description(中に itemize)も入れている
- `scenarios.rs` に `common_packages` を追加した。5 文書が成功し、error と未解決の参照が無く、1
ページの PDF ができることを確認する。`scenarios.rs` は CI の `integration` job(dev image で
latexmk を host backend として実行)と `sandbox`
job(`TEXRUN_TEST_BACKEND=container`)の両方で走るので、両 backend
を検証できる。engine-image workflow の `verify` でも走る
- #68(`!pdfTeX error:` の parser 対応)との整合
- #68 の log fixture `pdftex-missing-font` は、cm-super が無いことを前提にした
`ecrm1000` で失敗させていた。この PR で dev image に cm-super が入るので、Type1 の無い
`cmntt10`(cmextra)を使う文書に変えた。log を再生成し、`real_logs.rs` の期待値と
`regenerate.sh` のコメントを更新した。ほかの log は timestamp しか変わらないので戻している
- `skills/texrun/reference/errors.md` と docs/cli.md の font 不足の例を
`cmntt10` に変えた。errors.md は、Type1 のある font(既定の CM、T1、lmodern、mathptmx /
helvet / mathpazo)に切り替えるよう案内する。itemize や T1 でも失敗するなら engine image 0.1.0
なので、新しい image を使うよう書いた
- docs: engine-image.md のライセンス表に font と依存パッケージを追加し(`cm-super` /
`cm-super-minimal`、URW の Type1 は GPL + font exception)、PDF への font
埋め込みについて追記した。development.md(dev image の内容と version)と security.md(§3.4・§4
の image 構成)も更新した

### パッケージの選定

| 候補 | image layer | sources tar への追加 | 結果 |
| --- | --- | --- | --- |
| `cm-super-minimal` | +6.8 MB | cm-super source(約 65 MiB) | 10pt の font
しか入っていない。`itemize` の 10pt 文書は通るが、11pt
文書・見出し(`sfbx1440`)・脚注(`tcrm0800`)で失敗するので不採用 |
| **`cm-super`** | +63 MB | cm-super source(約 65 MiB)+ `pfb2t1c2pfb` |
T1 / TS1 の全サイズ。LaTeX の既定の font で必要になるので採用 |
| **`lmodern`** | +39 MB | ほぼ 0(source package `lmodern` は既存の
`fonts-lmodern` と同じ。`xfonts-utils` などが約 2 MiB) | `\usepackage{lmodern}`
は T1 文書の定番なので採用。font 本体の `fonts-lmodern` はもともと `texlive-latex-base`
の依存で入っていて、LaTeX 用のファイル(sty/fd/tfm)だけが無かった |
| **`texlive-fonts-recommended`** | +19 MB | 0(source package
`texlive-base` は既存) | PSNFSS(Times・Helvetica・Courier・Palatino
など)。論文でよく使われ、source は増えないので採用 |
| `tex-gyre` など | — | — | 追加しない(必要になったら別 Issue で) |

- ライセンス: `cm-super` は GPL-2.0-or-later(font exception 付き)、Latin Modern は
GUST Font License(LPPL の変種)。依存の `pfb2t1c2pfb` は GPL、`xfonts-utils` /
`xfonts-encodings` / `libfontenc` は MIT / X11。いずれも PDF への font
埋め込みは許されている
- 新しく入る source package は
`cm-super`、`pfb2t1c2pfb`、`xfonts-utils`、`xfonts-encodings`、`libfontenc`
の 5 つ(`dpkg-query` の差分で確認)

### サイズ

| | 修正前(main) | 修正後 |
| --- | --- | --- |
| engine image(ローカル build、arm64、圧縮 / 展開後) | 171.4 MB / 657 MB | 250.9 MB
/ 856 MB |
| dev image(圧縮 / 展開後) | 431.3 MB / 1.67 GB | 510.8 MB / 1.87 GB |
| sources tar | 1,230,028,800 B(v0.1.0 の asset) | 1,299,312,640 B(この PR
の engine-image workflow の sources job、148 source packages)。+69.3 MB(+66
MiB)で、上限 2 GiB に対する余裕は 848,170,368 B(約 809 MiB) |

## 確認方法

- [x] `cargo check --workspace --all-targets --all-features --locked`
- [x] `cargo fmt --all -- --check`
- [x] `cargo clippy --workspace --all-targets --all-features --locked --
-D warnings`
- [x] `cargo test --workspace --all-features --locked`(host)
- [x] dev image(この PR の Dockerfile で build)で `TEXRUN_REQUIRE_TEXLIVE=1
TEXRUN_REQUIRE_PREVIEW_TOOLS=1 cargo test --workspace --all-features
--locked`: 全部成功
- [x] ローカル build の engine image で、CI の sandbox job と同じ container
テスト一式(`TEXRUN_TEST_BACKEND=container TEXRUN_REQUIRE_SANDBOX=1
TEXRUN_REQUIRE_TEXLIVE=1`): 全部成功、ignored 0
- [x] 修正前の image(main の engine image、既存の dev image)では `common_packages`
が `Font tcrm0900 at 600 not found` で失敗することを確認した
- [x] 生成された PDF の font は、`pdffonts` で見るとすべて Type 1 だった(bitmap は無い)
- workflow は変えていないので actionlint は対象外。engine-image workflow の dry
run(verify / build / sources)はこの PR で走る

## 関連 Issue

Closes #65

修正版 image の公開(v0.1.1 の tag push と release)は、merge 後に owner の判断で行う。この PR
では公開しない。

## 補足

- 修正前は、この font error が diagnostics に error として出ていなかった(`!pdfTeX error:`
の行が parser で拾われない)。parser 側は #66 で扱っているので、この PR では触っていない
- image は約 +80 MB(圧縮)大きくなる。cm-super が大部分を占めるが、LaTeX の既定の font(T1 /
TS1)なので削れない

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@nishide-dev nishide-dev mentioned this pull request Oct 6, 2026
2 tasks done
nishide-dev added a commit that referenced this pull request Oct 6, 2026
## 概要

v0.1.1 を公開するため、版を 0.1.1 に上げます。

## 変更内容

- `Cargo.toml` の workspace と内部 crate の版を 0.1.1 に(`Cargo.lock` も更新)
- README、docs/engine-image.md、skills/texrun/reference/setup.md の版表記を
0.1.1 に(docs/development.md のリリース手順の版表記も)

v0.1.1 に含まれる主な変更:
- engine image / dev image に Type1
font(cm-super、lmodern、texlive-fonts-recommended)を追加し、itemize や T1
を使う一般的な文書が compile できるように(#65、PR #67)
- `!pdfTeX error:` を error diagnostic として報告し、失敗した compile には必ず error
を返す(#66、PR #68)
- Agent Skill と Claude Code の plugin marketplace(#63、PR #64)

## 確認方法

- [x] `cargo test --workspace --all-features --locked`
- [x] `git grep -n '0\.1\.0' -- README.md docs/ skills/`
で残りは履歴・説明上の記述のみ(release notes の初版の例、engine image 0.1.0 の不具合の説明)

## 補足

merge 後に main へ `v0.1.1` の tag を push し、engine image と release(notes
付き)を自動公開します。texrun 0.1.0 は既定で engine image 0.1.0 を使うため、font の修正を得るには
texrun を 0.1.1 に上げる必要があります(release notes に追記予定)。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report pdfTeX errors that the log parser misses

1 participant