Skip to content

Improve error handling and the output file lifecycle - #77

Merged
mapitman merged 1 commit into
mainfrom
bugfix/error-handling-output-lifecycle
Oct 14, 2026
Merged

mapitman merged 1 commit into
mainfrom
bugfix/error-handling-output-lifecycle

Conversation

@mapitman

Copy link
Copy Markdown
Owner
  • MDVIEW_DIR and the Snap temp dir use MkdirAll, so nested paths work.
  • check() writes to stderr, names the failing path, and shows the Snap hint only for permission and not-found errors. Render errors go through check() too.
  • writeOutput closes the file explicitly and returns Sync and Close errors.
  • Stale generated temp files (mdview<32 hex>.html, older than 24 hours) are removed from the temp directory before a new file is written. Cleanup runs only when -o is not given.
  • Mermaid detection uses the AST (mermaid.Kind), not a string match on the HTML.
  • Updates CLAUDE.md.

Tests cover hasMermaidBlock, embedMermaidScript, getTempDir, writeOutput and removeStaleTempFiles. I also checked the error output and exit codes against the built binary.

Closes #68

MDVIEW_DIR and the Snap temp directory are created with MkdirAll, so nested paths work. check() now writes to stderr, names the failing path, and shows the Snap hint only for permission and not-found errors, not for every failure.

The output file is written by writeOutput, which closes the file explicitly and returns Sync and Close errors. Before, log.Fatal skipped the deferred Close and those errors were dropped. Render errors now go through check().

Generated temp files older than 24 hours are removed from the temp directory before a new one is written. Only names that match mdview<32 hex>.html are touched.

Mermaid detection now looks for a mermaid block in the AST, so raw HTML that mentions class="mermaid" no longer adds the 2.6 MB script.

Closes #68
@mapitman
mapitman merged commit bc8a37a into main Oct 14, 2026
2 checks passed
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.

Improve error handling and the output file lifecycle

1 participant