Skip to content

Avoid truncating files when sqlformat options are invalid - #901

Open
RamiNoodle733 wants to merge 1 commit into
andialbrecht:masterfrom
RamiNoodle733:fix/cli-validate-before-open
Open

RamiNoodle733 wants to merge 1 commit into
andialbrecht:masterfrom
RamiNoodle733:fix/cli-validate-before-open

Conversation

@RamiNoodle733

Copy link
Copy Markdown

sqlformat --in-place currently opens the input path for writing before formatter options are validated. Because opening with w truncates immediately, an invalid formatting option such as --indent_width 0 can destroy the input file even though formatting fails.

This moves formatter-option validation ahead of output-stream creation, so invalid options return an error without touching the destination. Normal output selection and formatting behavior are otherwise unchanged.

A focused regression test verifies that an invalid in-place invocation returns an error and preserves the original file contents.

Validation: the change was reviewed against current master. I could not run the repository test suite locally because this automation environment cannot resolve GitHub for a checkout, so no local pytest result is claimed.

AI assistance was used to identify the destructive ordering bug, inspect repository guidance, and prepare the focused fix and regression coverage.

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