Atom-beautify: Can't save files after updating (if file formatting is not changed by Atom Beautify when saving)

Created on 22 Nov 2017  路  26Comments  路  Source: Glavin001/atom-beautify

Can't save files after updating!

bug high priority published

Most helpful comment

Update: Please try v0.30.9

cc @ejpcmac

All 26 comments

same!

same , i have Beautify on Save option checked on Typescript

same

Same for C, C++ and Rust with Beautify on Save enabled. Works correctly when beautifying by hand before saving with the option disabled.

same!

Can you describe what happens when you try to save? Does it beautify and not save? Something else? Can you also confirm you are on Atom 1.21 or later?

In my case the beautifying works, it's just that the file is not saved. As if atom-beautify prevents it. Because as soon as I disable the beautifying on save it works fine.

@szeck87 Doing some tests with the Beautify on Save option enabled:

  • If I edit the code in a way it is not correctly formatted, it formats the code and saves the file correctly.
  • If I edit the code in a way it is correctly formatted, but different, it does not save.

Can you check the console to see if it's throwing an error?

Wether it works or not, I get the same warning:

(node:2941) DeprecationWarning: Calling an asynchronous function without callback is deprecated.

However, I get a maybe more interesting error following these steps:

  1. edit a file in a way it is different but correctly formated,
  2. (optional) try to save the file: it does not work,
  3. with auto-save enabled, focus on another window or the console.

You then get the following error:

Uncaught Error: ENOENT: no such file or directory, unlink '/home/***/***/.atom-beautify.myfile.c'

I see in the last commits there was a change to use the onWillSave event. There could be some problems there.

From what I can gather stepping through the code, is that the beautify function never resolves the Promise it returns unless the beautify process either fails or if oldText isnt text. (So if the beautification doesn't change the text, the promise is not resolved.)

The 'will-save' event is emitted in a function called Emitter.prototype.emitAsync which collects the promises the event callbacks return. I guess Atom will then wait for all the promises to resolve before writing the final text to disc.

So if the formatter doesn't change the text, that prevents Atom from saving the file.

Correct, there was a change. Before that change, it would save files twice: once after telling it to save, after it does that Atom Beautify beauties the file, then Atom Beautify saves it again. With the change last night, Atom waits for Atom Beautify to beautify the file, then saves.

And indeed, adding

        else
          setTimeout( -> resolve(text), 0)

to that if oldText isnt text allows correctly formatted text to save again.

@exoticorn thanks for the findings. So in a nutshell, if you make changes to the file but in a way it's formatted properly (in which case Atom Beautify doesn't make changes), it fails. Correct?

Yes exactly. The workaround (other than my temporary fix above) is to just insert a random space somewhere that gets removed by the formatter. Then the file saves correctly. ;)

Bug related to https://github.com/Glavin001/atom-beautify/pull/1924

I'm working on a fix right now.

Please provide an example code so I can quickly reproduce and ensure the bug fix works.

Reproduce:

1)

<!doctype html>
<html>

<head>
<title>Test Page</title>
</head>

<body>
<h1>Hello</h1>
<p>
World!
</p>
</body>

</html>

2) Save, which results in:

<!doctype html>
<html>

  <head>
    <title>Test Page</title>
  </head>

  <body>
    <h1>Hello</h1>
    <p>
      World!
    </p>
  </body>

</html>

3) Change <p> tag to <a> tag, such that a change is detected, however the formatting is still correct:

image

4) File is unsaved. Saving does not work.

Published the fix recommended by @exoticorn : https://github.com/Glavin001/atom-beautify/issues/1949#issuecomment-346347191

Patch version 0.30.8

Please try and let me know!

Sorry all, missed that use case when I made this change. Please test the fix @Glavin001 put out and let us know if there are any more issues.

Cheers @Glavin001 !

Just updated and everything works great again - it saves with and without beautifying.

No worries @szeck87 - we are, after all, only human. It's blazing fast tho. So I love the change :-)

I get this error after updating, on Atom start:

nexpected , in /home/***/.atom/packages/atom-beautify/src/beautify.coffee:138:43
Hide Stack Trace
SyntaxError: unexpected ,
  at /home/***/.atom/packages/atom-beautify/src/beautify.coffee:138:43

Edit: After uninstalling and reinstalling the package, it works! Thanks!

Update: Please try v0.30.9

cc @ejpcmac

Chiming in, Im not sure wether this is related or if there is by chance an issue with another package at the exact same time.. but right now, with 0.30.9, Atom freezes with just a busy-signal and the text "Autocomplete failure".

EDIT: I tried disabling this package and the issue is still there.. so nvm, seems to be issues with a different package.

Ok @Glavin001, reinstallation made it work because I am now indeed at v0.30.9. Works great! Thanks again :)

Was this page helpful?
0 / 5 - 0 ratings