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

rake ember:compile returns 0 exit code even with failed compilation #417

Closed
wireframe opened this issue Mar 17, 2016 · 20 comments
Closed

rake ember:compile returns 0 exit code even with failed compilation #417

wireframe opened this issue Mar 17, 2016 · 20 comments

Comments

@wireframe
Copy link
Contributor

compiling the app via rake appears like everything is fine, but grepping my log/ember-appname.development.log log file is littered with error messages like this:

Package: json-stable-stringify
Required by: frontend / broccoli-asset-rev
  * Specified: 1.0.1
  * Installed: (not installed)
$ rake ember:compile && echo $?
$ 0

raising an error with a truncated (or full) error from the shell/log would be hugely helpful.

@seanpdoyle
Copy link
Contributor

@wireframe thanks, this is certainly a bug.

I'll look into it.

@seanpdoyle
Copy link
Contributor

@wireframe on further inspection, things might be behaving properly.

The ember:compile Rake task depends on ember:install, which would install the missing dependencies.

Other than the logs containing output about missing dependencies (which might come from ember-cli-dependency-checker), what behavior are you seeing that indicates that the build is failing?

@wireframe
Copy link
Contributor Author

after running rake ember:compile with the failed state, I reload my rails app and get an error from the ember controller saying that the index.html file can not be found.

NOTE: I've disabled the auto-rebuild with each web request due to other issues.

@seanpdoyle
Copy link
Contributor

@wireframe I've tried to reproduce your issues with https://github.com/seanpdoyle/ember-cli-rails-heroku-example, but I'm having some trouble. The ember:install Rake dependency seems to be preventing me from compiling without a necessary dependency.

Could you pull https://github.com/seanpdoyle/ember-cli-rails-heroku-example down and try to reproduce? If you're able to, could you share the steps it took on this issue? If there are code changes required to make the app more similar to your current project, could you fork it and push a branch?

@klaustopher
Copy link

I just ran into an issue as well ... I had an issue on one machine, that ~/.config/configstore/ember-cli.json was owned by root and ember-cli could not change it.

$ RAILS_ENV=staging bin/rake ember:compile
$ echo $?
0

The command finishes successfully, but the app is not available and if I look into the log file, this:

$ cat log/ember-demandcheck.staging.log
/srv/www/app/releases/20160317152940/demandcheck/node_modules/ember-cli/node_modules/configstore/index.js:53
                throw err;
                      ^
Error: EACCES, permission denied '/home/deploy/.config/configstore/ember-cli.json'
You don't have access to this file.

    at Object.fs.openSync (fs.js:432:18)
    at Object.fs.readFileSync (fs.js:286:15)
    at Object.create.all.get (/srv/www/optisure_staging/releases/20160317152940/demandcheck/node_modules/ember-cli/node_modules/configstore/index.js:34:26)
    at Object.Configstore (/srv/www/optisure_staging/releases/20160317152940/demandcheck/node_modules/ember-cli/node_modules/configstore/index.js:27:44)
    at clientId (/srv/www/optisure_staging/releases/20160317152940/demandcheck/node_modules/ember-cli/lib/cli/index.js:22:21)
    at module.exports (/srv/www/optisure_staging/releases/20160317152940/demandcheck/node_modules/ember-cli/lib/cli/index.js:65:19)
    at /srv/www/optisure_staging/releases/20160317152940/demandcheck/node_modules/ember-cli/bin/ember:26:3
    at /srv/www/optisure_staging/releases/20160317152940/demandcheck/node_modules/ember-cli/node_modules/resolve/lib/async.js:44:21
    at ondir (/srv/www/optisure_staging/releases/20160317152940/demandcheck/node_modules/ember-cli/node_modules/resolve/lib/async.js:187:31)
    at /srv/www/optisure_staging/releases/20160317152940/demandcheck/node_modules/ember-cli/node_modules/resolve/lib/async.js:153:39

This is particularly annoying if this happens in assets:precompile because it gets totally hidden and we only see that the app is not there because our customers are seeing 500s.

@klaustopher
Copy link

As a side note ... If i.e. bower-github.yml is not writable, the ember:install fails with all bells and whistles 😄

$ RAILS_ENV=staging bin/rake ember:compile --trace
** Invoke ember:compile (first_time)
** Invoke ember:install (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute ember:install
          ERROR: Failed command: `/usr/local/bin/bower prune && /usr/local/bin/bower install`
          OUTPUT:

Error: EACCES, permission denied '/home/deploy/.config/configstore/bower-github.yml'
You don't have access to this file.

    at Object.fs.openSync (evalmachine.<anonymous>:432:18)
    at Object.fs.readFileSync (evalmachine.<anonymous>:286:15)
    at Object.create.all.get (/usr/local/lib/node_modules/bower/lib/node_modules/configstore/index.js:34:29)
    at Object.Configstore (/usr/local/lib/node_modules/bower/lib/node_modules/configstore/index.js:27:44)
    at readCachedConfig (/usr/local/lib/node_modules/bower/lib/config.js:19:23)
    at defaultConfig (/usr/local/lib/node_modules/bower/lib/config.js:11:12)
    at Object.<anonymous> (/usr/local/lib/node_modules/bower/lib/index.js:16:32)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

@seanpdoyle
Copy link
Contributor

@klaustopher thanks for the additional information.

~/.config/configstore/ember-cli.json was owned by root and ember-cli could not change it.

Error: EACCES, permission denied '/home/deploy/.config/configstore/bower-github.yml'
You don't have access to this file.

I'm not familiar with either of those files or the directory they're located in. Could you explain their significance, and maybe link to some documentation about them?

@klaustopher
Copy link

ehrm, I have no idea what they are for exactly ... I think it might have something to do with this: https://www.npmjs.com/package/configstore

But the problem is, not with this file exactly. The problem is, that an error happens during rake ember:compile but the command still finishes with a success state whereas if an error during rake ember:install happens, the whole rake tasks fails (as it is supposed to). Sorry if I didn't make that clear ;)

@seanpdoyle
Copy link
Contributor

@klaustopher @wireframe using https://github.com/seanpdoyle/ember-cli-rails-heroku-example as a base application, I've done some digging and extracted the shell command that ember-cli-rails will generate for a given application.

Running it (with tee):

~/src/ember-cli-rails-heroku-example/frontend master
❯ /Users/seanpdoyle/src/ember-cli-rails-heroku-example/frontend/node_modules/.bin/ember build --environment 'development' --output-path '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/tmp/ember-cli/apps/frontend' | /usr/bin/tee -a '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/log/ember-frontend.development.log'

Missing npm packages: 
Package: ember-data
  * Specified: 1.13.15
  * Installed: (not installed)

Run `npm install` to install missing dependencies.


~/src/ember-cli-rails-heroku-example/frontend master
❯ echo $?
0

Without the call to tee:

~/src/ember-cli-rails-heroku-example/frontend master
❯ /Users/seanpdoyle/src/ember-cli-rails-heroku-example/frontend/node_modules/.bin/ember build --environment 'development' --output-path '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/tmp/ember-cli/apps/frontend'                                                                                                           

Missing npm packages: 
Package: ember-data
  * Specified: 1.13.15
  * Installed: (not installed)

Run `npm install` to install missing dependencies.


~/src/ember-cli-rails-heroku-example/frontend master
❯ echo $?
1

It looks like piping the output to tee is hiding the exit status of the initial command.

I'll investigate further.

@seanpdoyle
Copy link
Contributor

@thoughtbot/shell can anyone help with #417 (comment)?

@klaustopher
Copy link

The strange thing is, that ember:install does fail and ember:compile does not ... Are they handled differently?

@seanpdoyle
Copy link
Contributor

Using set -o pipefail corrects it:

~/src/ember-cli-rails-heroku-example/frontend master
❯ set -o pipefail; /Users/seanpdoyle/src/ember-cli-rails-heroku-example/frontend/node_modules/.bin/ember build --environment 'development' --output-path '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/tmp/ember-cli/apps/frontend' | /usr/bin/tee -a '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/log/ember-frontend.development.log'

Missing npm packages: 
Package: ember-data
  * Specified: 1.13.15
  * Installed: (not installed)

Run `npm install` to install missing dependencies.


~/src/ember-cli-rails-heroku-example/frontend master
❯ echo $?
1

@seanpdoyle
Copy link
Contributor

@klaustopher they're not "handled" different, in that they're both generated by EmberCli::Command and run through EmberCli::Runner, but they're different commands.

@klaustopher
Copy link

Then it's really, really strange, that they handle failures differently, I'll take a look tomorrow morning, workday is over ;)

seanpdoyle added a commit that referenced this issue Mar 17, 2016
Closes [#417].

The following is the command `ember-cli-rails` generates for `rake
ember:compile`. It was generated using [the example application][repo].

```bash
/Users/seanpdoyle/src/ember-cli-rails-heroku-example/frontend/node_modules/.bin/ember build --environment 'development' --output-path '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/tmp/ember-cli/apps/frontend' | /usr/bin/tee -a '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/log/ember-frontend.development.log'

Pipes are streaming, so the pipe to `tee` will open before the first
program finishes writing, potentially ignoring a non-zero exit status.

The solution is to set the [`pipefail`][docs] option for the generated
sub-command.

[repo]: https://github.com/seanpdoyle/ember-cli-rails-heroku-example
[#417]: #417
[docs]: http://www.gnu.org/software/bash/manual/html_node/Pipelines.html
@klaustopher
Copy link

Looking at https://github.com/thoughtbot/ember-cli-rails/blob/master/lib/ember_cli/shell.rb#L44, the install commands are executed directly by the runner, whereas the compile step (https://github.com/thoughtbot/ember-cli-rails/blob/master/lib/ember_cli/shell.rb#L17) is run by an EmberCli::Command

@seanpdoyle
Copy link
Contributor

@wireframe @klaustopher could you try the set-pipefail branch:

# Gemfile

gem "ember-cli-rails", github: "thoughtbot/ember-cli-rails", branch: "set-pipefail"

seanpdoyle added a commit that referenced this issue Mar 17, 2016
Closes [#417].

The following is the command `ember-cli-rails` generates for `rake
ember:compile`. It was generated using [the example application][repo].

```bash
/Users/seanpdoyle/src/ember-cli-rails-heroku-example/frontend/node_modules/.bin/ember build --environment 'development' --output-path '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/tmp/ember-cli/apps/frontend' | /usr/bin/tee -a '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/log/ember-frontend.development.log'

Pipes are streaming, so the pipe to `tee` will open before the first
program finishes writing, potentially ignoring a non-zero exit status.

The solution is to set the [`pipefail`][docs] option for the generated
sub-command.

[repo]: https://github.com/seanpdoyle/ember-cli-rails-heroku-example
[#417]: #417
[docs]: http://www.gnu.org/software/bash/manual/html_node/Pipelines.html
@klaustopher
Copy link

version 0.7.2

$ ls -lah ~/.config/configstore/ember-cli.json
-rw------- 1 root wheel 56 Mär 17 14:14 /Users/klaustopher/.config/configstore/ember-cli.json

$ bundle show ember-cli-rails
/Users/klaustopher/.rvm/gems/ruby-2.2.2/gems/ember-cli-rails-0.7.2

$ bin/rake ember:compile
$

set-pipefail branch:

$ ls -lah ~/.config/configstore/ember-cli.json
-rw------- 1 root wheel 56 Mär 17 14:14 /Users/klaustopher/.config/configstore/ember-cli.json

$ bundle show ember-cli-rails
/Users/klaustopher/.rvm/gems/ruby-2.2.2/bundler/gems/ember-cli-rails-06020e015d4d

$ bin/rake ember:compile
          ERROR: Failed command: `set -o pipefail; /Users/klaustopher/Projects/application/feed/node_modules/ember-cli/bin/ember build --environment 'development' --output-path '/Users/klaustopher/Projects/application/tmp/ember-cli/apps/feed' | /usr/bin/tee -a '/Users/klaustopher/Projects/application/log/ember-feed.development.log'`
          OUTPUT:
            /Users/klaustopher/Projects/application/feed/node_modules/configstore/index.js:53
                throw err;
                ^

Error: EACCES: permission denied, open '/Users/klaustopher/.config/configstore/ember-cli.json'
You don't have access to this file.

    at Error (native)
    at Object.fs.openSync (fs.js:584:18)
    at Object.fs.readFileSync (fs.js:431:33)
    at Object.create.all.get (/Users/klaustopher/Projects/Clark/application/feed/node_modules/configstore/index.js:34:26)
    at Object.Configstore (/Users/klaustopher/Projects/Clark/application/feed/node_modules/configstore/index.js:27:44)
    at clientId (/Users/klaustopher/Projects/Clark/application/feed/node_modules/ember-cli/lib/cli/index.js:22:21)
    at module.exports (/Users/klaustopher/Projects/Clark/application/feed/node_modules/ember-cli/lib/cli/index.js:65:19)
    at /Users/klaustopher/Projects/Clark/application/feed/node_modules/ember-cli/bin/ember:26:3
    at /Users/klaustopher/Projects/Clark/application/feed/node_modules/resolve/lib/async.js:44:21
    at ondir (/Users/klaustopher/Projects/Clark/application/feed/node_modules/resolve/lib/async.js:187:31)

Looks good to me! 👍

I cannot test on an ubuntu machine before tomorrow morning, but I just tested that set -o pipefail is also available on our machines. Just a quick glance through the net told me that the option might not be available under dash. So I will check tomorrow if this works on a vanilla ubuntu machine.

seanpdoyle added a commit that referenced this issue Mar 17, 2016
Closes [#417][#417].

The following is the command `ember-cli-rails` generates for `rake
ember:compile`. It was generated using [the example application][repo].

```bash
/Users/seanpdoyle/src/ember-cli-rails-heroku-example/frontend/node_modules/.bin/ember build --environment 'development' --output-path '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/tmp/ember-cli/apps/frontend' | /usr/bin/tee -a '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/log/ember-frontend.development.log'

Pipes are streaming, so the pipe to `tee` will open before the first
program finishes writing, potentially ignoring a non-zero exit status.

The solution is to set the [`pipefail`][docs] option for the generated
sub-command.

[repo]: https://github.com/seanpdoyle/ember-cli-rails-heroku-example
[#417]: #417
[docs]: http://www.gnu.org/software/bash/manual/html_node/Pipelines.html
seanpdoyle added a commit that referenced this issue Mar 17, 2016
Closes [#417][#417].

The following is the command `ember-cli-rails` generates for `rake
ember:compile`. It was generated using [the example application][repo].

```bash
/Users/seanpdoyle/src/ember-cli-rails-heroku-example/frontend/node_modules/.bin/ember build --environment 'development' --output-path '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/tmp/ember-cli/apps/frontend' | /usr/bin/tee -a '/Users/seanpdoyle/src/ember-cli-rails-heroku-example/log/ember-frontend.development.log'
```

Pipes are streaming, so the pipe to `tee` will open before the first
program finishes writing, potentially ignoring a non-zero exit status.

The solution is to set the [`pipefail`][docs] option for the generated
sub-command.

[repo]: https://github.com/seanpdoyle/ember-cli-rails-heroku-example
[#417]: #417
[docs]: http://www.gnu.org/software/bash/manual/html_node/Pipelines.html
@seanpdoyle
Copy link
Contributor

@wireframe @klaustopher could you try the latest version of the (now poorly named) set-pipefail branch?

It uses an alternative (hopefully cross platform) solution.

@klaustopher
Copy link

see comment in the PR, it fails again :/

seanpdoyle added a commit that referenced this issue Mar 18, 2016
Closes [#417].

Instead of piping output to the [`tee`][tee] command (which was
previously swallowing non-zero exit statuses), capture output
from `Open3.capture2e` and write to both the specified log file and
`STDOUT`.

[#417]: #417
[tee]: http://man7.org/linux/man-pages/man1/tee.1.html
@seanpdoyle
Copy link
Contributor

@klaustopher @wireframe could you try out the remove-tee branch instead:

# Gemfile

gem "ember-cli-rails", github: "thoughtbot/ember-cli-rails", branch: "remove-tee"

seanpdoyle added a commit that referenced this issue Mar 18, 2016
Closes [#417].

Instead of piping output to the [`tee`][tee] command (which was
previously swallowing non-zero exit statuses), capture output
from `Open3.capture2e` and write to both the specified log file and
`STDOUT`.

[#417]: #417
[tee]: http://man7.org/linux/man-pages/man1/tee.1.html
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

3 participants