Skip to content

fix: replace sync file read with async fs/promises and add error handling#322

Open
comzzy-comzzy wants to merge 1 commit into
Toolbox-Lab:mainfrom
comzzy-comzzy:fix/async-toml-file-reading
Open

fix: replace sync file read with async fs/promises and add error handling#322
comzzy-comzzy wants to merge 1 commit into
Toolbox-Lab:mainfrom
comzzy-comzzy:fix/async-toml-file-reading

Conversation

@comzzy-comzzy

Copy link
Copy Markdown

Summary

Fixes #307 — Script crashes or hangs when reading the core TOML taxonomy file unsafely.

Changes

  • Replaced the dummy index.js with a full async implementation using fs/promises
  • Reads crates/core/src/taxonomy/data/contract.toml asynchronously (non-blocking)
  • Explicitly specifies utf-8 encoding to prevent raw Buffer returns
  • Added targeted try/catch with handling for specific Node.js error codes:
    • ENOENT — file not found: outputs actionable message about initializing the crates/core submodule
    • EACCES — permission denied: warns about file permission boundaries
    • EBUSY / EPERM — file locked or operation not permitted
    • Generic fallback for unexpected errors
  • Parses the TOML content using @iarna/toml and outputs the taxonomy as formatted JSON
  • All error messages are clean CLI-friendly diagnostics, no raw V8 stack traces

Testing

  • Verified the script runs without blocking the event loop
  • Tested ENOENT scenario (missing file) — outputs contextual guidance
  • Tested EACCES scenario (restricted permissions) — outputs permission warning
  • Tested happy path — successfully reads and parses the TOML taxonomy

Closes #307

…ling

Resolves Toolbox-Lab#307

- Replace dummy implementation with robust async TOML file reader
- Use fs/promises for non-blocking file I/O with utf-8 encoding
- Add targeted try/catch handling for ENOENT, EACCES, and EISDIR errors
- Output actionable CLI diagnostic messages instead of raw stack traces
- Parse TOML content using @iarna/toml and output as formatted JSON
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.

Script Crashes or Hangs When Reading the Core TOML Taxonomy File Unsafely

1 participant