Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dfmt erase the file when it fails to format it #568

Closed
bitcuits opened this issue Oct 5, 2022 · 1 comment
Closed

dfmt erase the file when it fails to format it #568

bitcuits opened this issue Oct 5, 2022 · 1 comment

Comments

@bitcuits
Copy link

bitcuits commented Oct 5, 2022

If a source file is not formatted correctly then dfmt sometimes erases the content of the file

File sample

### This file should not be erased just because it is not formatted correctly

The .editconfig used

# top-most EditorConfig file
root = true

# D source
[*.{d,di}]
dfmt_brace_style = stroustrup
dfmt_split_operator_at_line_end = true
indent_size = 4
soft_max_line_length = 80
dfmt_soft_max_line_length = 120
dfmt_keep_line_breaks = true
# dfmt_compact_labeled_statements = true
# conditional_newline_indent = true
# dfmt_template_constraint_style = conditional_newline
@WebFreak001
Copy link
Member

are you working with --inplace? The regular formatting returns with exit code 1 if it hard-fails like this, which should instruct you not to write anything to the file.

WebFreak001 added a commit to WebFreak001/dfmt that referenced this issue Oct 5, 2022
Now when an error in formatting happens, it never outputs anything and
doesn't override the file when working inplace.

Additionally dfmt is no longer able to fail in the middle of a file, as
now we first write everything to a buffer and only if everything was
successful, that buffer is printed to stdout or written to the inplace
file.

This should also guard against segfaults with inplace file formatting
erasing parts of the file, as well as the user thinking it was
successful, even though dfmt didn't finish properly.
WebFreak001 added a commit to WebFreak001/dfmt that referenced this issue Oct 5, 2022
Now when an error in formatting happens, it never outputs anything and
doesn't override the file when working inplace.

Additionally dfmt is no longer able to fail in the middle of a file, as
now we first write everything to a buffer and only if everything was
successful, that buffer is printed to stdout or written to the inplace
file.

This should also guard against segfaults with inplace file formatting
erasing parts of the file, as well as the user thinking it was
successful, even though dfmt didn't finish properly.
WebFreak001 added a commit to WebFreak001/dfmt that referenced this issue Oct 5, 2022
Now when an error in formatting happens, it never outputs anything and
doesn't override the file when working inplace.

Additionally dfmt is no longer able to fail in the middle of a file, as
now we first write everything to a buffer and only if everything was
successful, that buffer is printed to stdout or written to the inplace
file.

This should also guard against segfaults with inplace file formatting
erasing parts of the file, as well as the user thinking it was
successful, even though dfmt didn't finish properly.
WebFreak001 added a commit to WebFreak001/dfmt that referenced this issue Oct 5, 2022
Now when an error in formatting happens, it never outputs anything and
doesn't override the file when working inplace.

Additionally dfmt is no longer able to fail in the middle of a file, as
now we first write everything to a buffer and only if everything was
successful, that buffer is printed to stdout or written to the inplace
file.

This should also guard against segfaults with inplace file formatting
erasing parts of the file, as well as the user thinking it was
successful, even though dfmt didn't finish properly.
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

No branches or pull requests

2 participants