Skip to content

feat: migrate engine layer to thiserror with CoraError enum (#86) - #143

Merged
ajianaz merged 1 commit into
developfrom
feat/thiserror-migration
Jun 2, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/thiserror-migration

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Migrate engine layer from anyhow to typed CoraError enum via thiserror = "2".

New file:

  • src/error.rs — CoraError enum with 17 variants

Modified (10 files):

  • Cargo.toml — added thiserror = "2"
  • src/main.rs — added mod error
  • engine/llm.rs, engine/review.rs, engine/scanner.rs, engine/cache.rs → Result<T, CoraError>
  • config/loader.rs, config/schema.rs → typed errors
  • git/diff.rs → typed errors
  • commands/review.rs → map_err(Into::into) for CoraError→anyhow conversion

CoraError variants: LlmRequest, LlmStatus, LlmParse, LlmStream, LlmJsonRepair, ConfigParse, ConfigRead, NoApiKey, DiffTooLarge, InvalidRef, GitCommand, NotInGitRepo, HeadDetached, CacheIo, CacheSerialize, ScannerError, AuthError, HookError, Timeout

Design decisions:

  • Engine layer → Result<T, CoraError> (typed, programmatic matching)
  • CLI layer → retains anyhow::Result (ergonomic, auto-converts via ?)
  • #[from] for reqwest::Error and std::io::Error (standard thiserror pattern)

Verification: 224 tests ✅ | clippy clean ✅ | fmt clean ✅ | local binary test ✅

Prerequisite for: #116 (pre-LLM rule engine needs typed error output)

⚠️ Cora pre-commit found 2 false positives on #[from] attributes — these are valid thiserror patterns (different types per variant, no conflict).

Closes #86

Co-Authored-By: codecoradev noreply@github.com

Replace anyhow with typed CoraError enum (17 variants) in engine layer:
- LLM: request, status, parse, stream, json repair, timeout
- Config: parse, read, no API key
- Git: invalid ref, command failure, not in repo, head detached
- Cache: I/O, serialize
- Scanner, auth, hook errors

CLI/command layer retains anyhow for ergonomics.
Engine layer returns Result<T, CoraError> for programmatic matching.

Prerequisite for #116 (rule engine needs typed error output).

224 tests pass, clippy clean, fmt clean.

Closes #86

Co-Authored-By: codecoradev <noreply@github.com>
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (2)

  • src/error.rs:72 — The #[from] std::io::Error on CacheIo generates a blanket From<std::io::Error> for CoraError. This means any function returning Result<T, CoraError> that calls something returning std::io::Error will silently convert the IO error into CacheIo, even when the IO error is unrelated to caching (e.g., config file reads, git operations). This can lead to misleading error messages. For example, std::env::current_dir() in open_repo() returns std::io::Error, and with ? it would be converted to CacheIo instead of a more appropriate variant.
  • src/error.rs:15 — The #[from] reqwest::Error on LlmRequest generates From<reqwest::Error> for CoraError. Since reqwest::Error can represent both request failures and response body read failures, this blanket conversion means any reqwest::Error will always become LlmRequest, even when it might be more appropriate as LlmStream or another variant. Additionally, this can conflict if other variants also try to use #[from] with overlapping error types.

Review powered by cora-cli · BYOK · MIT

@ajianaz
ajianaz merged commit 13cb6c8 into develop Jun 2, 2026
7 checks passed
@ajianaz
ajianaz deleted the feat/thiserror-migration branch June 2, 2026 16:12
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.

📦 Consider thiserror for typed error matching

1 participant