question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix crash when fixing file not owned by current user

See original GitHub issue

When running --fix stylelint attempts to chown its temp file back to the owner of the original file. This fails and causes stylelint to crash when the chown can not be completed. Other linting tools like prettier are able to rewrite files not owned by the current user so I would expect stylelint to be able to as well.

The Error is Error: EPERM: operation not permitted, chown '/Users/benscott/projects/stylelint-fixfail/style.css.4151106271'

I discovered this bug because I am running stylelint --fix as part of some integration tests for a tool that wraps stylelint and my tests failed on CI as the initial checkout of the files is performed by the root user but the tests (and thus stylelint --fix) is ran by the circleci user.

Which rule, if any, is the bug related to?

All autofixable rules.

What CSS / configuration is needed to reproduce the bug?

In a new folder, create:

A package.json:

{
  "name": "stylelint-fixfail",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "lint": "stylelint '*.css'",
    "lint:fix": "stylelint '*.css' --fix",
    "prettier": "prettier '*.css' --write"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "prettier": "1.14.2",
    "stylelint": "9.4.0"
  },
  "stylelint": {
    "rules": {
      "selector-pseudo-element-colon-notation": "double"
    }
  }
}

and a style.css:

.foo:before {top: 0;}

This css violates the selector-pseudo-element-colon-notation rule and autofixing should transform the file contents to be .foo::before {top: 0;} (note the double colon).

Which version of stylelint are you using?

9.4.0

Reproduction steps

  • npm install
  • Run npm run lint:fix and note that style.css is reformatted correctly, then reset the file back to its original content
  • sudo chown root style.css && sudo chmod 666 style.css to change the ownership of the file to be not-the-current-user but still be writable by all users.
  • Run npm run lint:fix Get the error message Error: EPERM: operation not permitted, chown '/Users/benscott/projects/stylelint-fixfail/style.css.4151106271' and the file is not autoformatted
  • Run npm run prettier and note that prettier can successfully reformat the file and maintain its ownership without crashing.

Does the bug relate to non-standard syntax (e.g. SCSS, Less etc.)?

It affects all syntaxes

What did you expect to happen?

The file to be autofixed successfully.

What actually happened (e.g. what warnings or errors did you get)?

The file was not autofixed. The following error was raised:

Error: EPERM: operation not permitted, chown '/Users/benscott/projects/stylelint-fixfail/style.css.4151106271'

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
golopotcommented, Mar 27, 2019

From #2992:

previously if the operation was cancelled or crashed while the styles were been written, the sources could be left in an inconsistent state.

If we switch to fs.writeFileSync, there will be at most one corrupt file in a cli run. I think it is acceptable, consider that crashes or unexpected poweroff should be rare. I assumed that ctrl + c will not preempt fs.writeFileSync, right?

0reactions
alexander-akaitcommented, Jun 25, 2019

/cc @kevinsawicki can you create minimum reproducible test repo? Maybey we can find other way to fix it, thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix You Don't Currently Have Permission to Access ...
Solution 1. Change the Ownership of the File/Folder (Recommend) · 1. Right-click on the folder to navigate to "Properties". · 2. Go to...
Read more >
Unable to display current owner - Microsoft Q&A
I have a folder in which n numbers of file is there but it is not getting opened. It is showing unable to...
Read more >
Fixing 'You don't currently have permission to access this folder'
Solution 2: Deselecting the 'Read Only' Option · Launch File Explorer, then right-click the affected folder. · Select Properties from the options.
Read more >
How to fix almost ANY Windows Bluescreen, Error, Crash OR ...
Fix Windows crashing, errors & bluecreens - Try it out! ... contained in this video is the sole responsibility of the user and...
Read more >
Fix “You don't currently have permission to access ... - YouTube
Fix “You don't currently have permission to access this folder” Windows 10, 8, 7Receiving popup error You Do Not Have Permission To Access ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found