Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Raise a better error when compiler is not found in PATH #48

Closed
lewis617 opened this issue Mar 17, 2017 · 10 comments
Closed

Raise a better error when compiler is not found in PATH #48

lewis617 opened this issue Mar 17, 2017 · 10 comments

Comments

@lewis617
Copy link

lewis617 commented Mar 17, 2017

When the compiler is not found we let OSError: [Errno 2] No such file or directory be thrown. We should return a better error and a better message like Executable {name} not found.

Full stacktrace of an example:

Traceback (most recent call last):
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask/app.py", line 2000, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask/app.py", line 1991, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask/app.py", line 1567, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask_cache/__init__.py", line 297, in decorated_function
    rv = f(*args, **kwargs)
  File "/Users/liuyiqi/code/src/opendata/app/home/views.py", line 9, in index
    return render_template('home.html')
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask/templating.py", line 134, in render_template
    context, ctx.app)
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/flask/templating.py", line 116, in _render
    rv = template.render(context)
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/liuyiqi/code/src/opendata/app/templates/home.html", line 3, in top-level template code
    {% extends 'layouts/base.html' %}
  File "/Users/liuyiqi/code/src/opendata/app/templates/layouts/base.html", line 26, in top-level template code
    {% compress 'css' %}
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/jac/extension.py", line 39, in _compress_block
    return self.compressor.compress(html, compression_type)
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/jac/base.py", line 103, in compress
    debug=self.config.compressor_debug)
  File "/Users/liuyiqi/venv/opendata/lib/python2.7/site-packages/jac/compressors/less.py", line 35, in compile
    stderr=subprocess.PIPE, cwd=None)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
@jaysonsantos
Copy link
Owner

Make sure less compiler is in your path

@lewis617
Copy link
Author

I did this:

npm install less  -g

but the problem is still there. What do you mean "Make sure less compiler is in your path"?

@lewis617
Copy link
Author

lewis617 commented Mar 17, 2017

I did this again:

sudo npm install less -g 

and the problem is solved. Thank you anyway.

@jaysonsantos
Copy link
Owner

I am leaving this open because we should make this error clear.
To test if it would work for your script just run which compiler_executable and if it returns a valid result, your python script should work

@jaysonsantos jaysonsantos changed the title OSError: [Errno 2] No such file or directory Raise a better error when compiler is not found in PATH Mar 17, 2017
@lewis617
Copy link
Author

I run the command in my project root:

which compiler_executable

and return nothing. I want to know how to run which compiler_executable,where to run? Can you give me more details?

@jaysonsantos
Copy link
Owner

In case of less the compiler executable is called lessc, if you run which lessc and it shows something, lessc is in your PATH variable and jac would be able to find it

@jaysonsantos
Copy link
Owner

To avoid this kind of problem, the executable path should be configurable, I've created #49 to tackle this

@lewis617
Copy link
Author

oh, I see what you mean. I run the which lessc, and return a valid result: /Users/liuyiqi/.nvm/versions/node/v7.1.0/bin/lessc.

@lewis617
Copy link
Author

Adding a config to override compilers executables is a good solution. The error came from nvm perhaps.

alanhamlett added a commit to alanhamlett/jinja-assets-compressor that referenced this issue Mar 18, 2017
@jaysonsantos
Copy link
Owner

fixed by #50

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants