Skip to content

fix: report output file write failures cleanly#1038

Open
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/cli-output-file-errors
Open

fix: report output file write failures cleanly#1038
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/cli-output-file-errors

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Motivation

Output-file creation failures could leak raw Java exceptions instead of clean CLI diagnostics. The original handleWriteFile[T](f: => T) also interpolated the by-name write expression while formatting errors, which could re-evaluate a failing write path.

Scenario sjsonnet master this PR
Missing output parent dir Java NoSuchFileException stack trace open path/out.json: no such file or directory
Malformed output path Java path exception detail open <path>: <message>
--multi --output-file file-list write failure raw write failure clean exit code 1 + stderr

Modification

  • Change handleWriteFile to take an eager path: String label and a by-name write thunk separately.
  • Route normal output-file writes, byte-renderer writes, YAML stream writes, and multi-mode file-list writes through handleWriteFile.
  • Normalize missing-file, malformed-path, and generic I/O failures into concise diagnostics.
  • Add JVM CLI regression tests for missing parents, malformed output paths, and multi-mode output-file failures.

Result

  • Output-file write failures return exit code 1 instead of throwing.
  • Error messages report the user path and do not leak Java exception class names in covered cases.
  • Successful stdout, file, YAML stream, and multi-output behavior is unchanged.

Verification

  • ./mill --no-daemon 'sjsonnet.jvm[3.3.8].test' sjsonnet.MainTests
  • ./mill --no-daemon 'sjsonnet.jvm[3.3.8].checkFormat'

@He-Pin He-Pin force-pushed the fix/cli-output-file-errors branch from 4b622f2 to 244001d Compare June 25, 2026 04:48
@He-Pin He-Pin marked this pull request as draft June 25, 2026 17:57
@He-Pin He-Pin marked this pull request as ready for review June 25, 2026 18:04
Motivation:

Some --output-file write failures, including multi-mode file-list writes, could bypass the existing write wrapper and surface raw Java exception details.

Modification:

Route normal output-file writes, byte/YAML output streams, and multi-mode file-list writes through handleWriteFile. Include the user path in errors and normalize missing, malformed, and IO path failures. Add JVM CLI regression tests for missing parents, malformed output paths, and multi-mode output-file failures.

Result:

Output-file write failures now return exit code 1 with concise diagnostics instead of stack traces or raw path exception classes.
@He-Pin He-Pin force-pushed the fix/cli-output-file-errors branch from e88687d to 5bc45e8 Compare June 25, 2026 19:04
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.

1 participant