-
Notifications
You must be signed in to change notification settings - Fork 54
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
Guard against FileNotFoundError #227
Conversation
python2+python3 compatibility: should use
|
sass.py
Outdated
@@ -50,6 +50,9 @@ | |||
#: (:class:`collections.Set`) The set of keywords :func:`compile()` can take. | |||
MODES = set(['string', 'filename', 'dirname']) | |||
|
|||
if PY2: | |||
FileNotFoundError = OSError | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of this, just use OSError
in the except
block
@asottile Yeah, I noticed the failing tests – updated as per your preference. |
# #208: cwd is always included in include paths, if possible | ||
try: | ||
include_paths = (os.getcwd(),) | ||
except OSError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worth calling out why this OSError
can occur, perhaps something like: "if the current working directory has been deleted, getcwd()
will raise"
might also be good to write a quick regression test to demonstrate this -- let me know if you'd like some help with this -- it should be pretty easy to start with something like this:
def test_compile_in_missing_dir(tmpdir):
does_not_exist = tmpdir.join('does_not_exist').ensure_dir()
with does_not_exist.as_cwd():
does_not_exist.remove()
# run a compile from here
I actually tried writing such a test, I'm not sure this ever worked:
|
So how do you want to proceed? |
I like the patch, I'm going to try and fix this upstream as well: sass/libsass#2513 |
It may also be time for us to ditch the 3.4.x releases and move to the 3.5 betas -- even though they're "beta" |
Any news on this? |
Yes! Upstream merged a change related to this -- though it still crashes just in a different way now:
Here's the full test I'm using: import sass
def test_compile_in_missing_dir(tmpdir):
f = tmpdir.join('f.scss')
f.write('a{color: red;}')
dne = tmpdir.join('does_not_exist').ensure_dir()
with dne.as_cwd():
dne.remove()
sass.compile(filename=str(f)) Looking back at previous versions, it seems this has never worked though: 0.13.2 - 0.13.7 have the
0.13.1 and 0.13.0 and 0.12.3 crash in the same way Even against the beta (which removes cwd from the search path):
So I think it's safe to say this never worked, and never will work :( |
Strange, because for me it worked as long as I pinned libsass to 0.13.1 … |
0.13.1 uses libsass 3.4.5 This line is going to crash if pwd is missing: https://github.com/sass/libsass/blob/3.4.5/src/context.cpp#L63 |
I ran into this issue in production –
os.getcwd()
may raise aFileNotFoundError
.