diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e991a20..515746f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +main +------ + +* Report the whole `ember build` failure in the `EmberCli::BuildError` + message, instead of only its first line. The line naming the file that + failed to build is rarely the first one the build tool writes, so a parse + error was reported with its message and line number but no way to tell + which file it came from + 0.14.0 ------ diff --git a/lib/ember_cli/build_monitor.rb b/lib/ember_cli/build_monitor.rb index 75cbf448..2503f4fd 100644 --- a/lib/ember_cli/build_monitor.rb +++ b/lib/ember_cli/build_monitor.rb @@ -41,6 +41,7 @@ def error_file_exists? def build_errors error_lines. + map(&:chomp). reject { |line| is_blank_or_backtrace?(line) }. reject { |line| is_deprecation_warning?(line) }. reject { |line| is_building_notice?(line) } @@ -75,11 +76,11 @@ def error_file end def raise_build_error! - backtrace = build_errors.first - message = "#{name.inspect} has failed to build: #{backtrace}" + errors = build_errors + message = "#{name.inspect} has failed to build: #{errors.join("\n")}" error = BuildError.new(message) - error.set_backtrace(backtrace) + error.set_backtrace(errors) fail error end diff --git a/spec/lib/ember_cli/build_monitor_spec.rb b/spec/lib/ember_cli/build_monitor_spec.rb index a9338434..9a3ec98b 100644 --- a/spec/lib/ember_cli/build_monitor_spec.rb +++ b/spec/lib/ember_cli/build_monitor_spec.rb @@ -56,6 +56,62 @@ end end + context "when the error file describes the file that failed to build" do + it "raises a BuildError reporting every line of the failure" do + error_file = error_file_with_contents( + [ + "Build failed.", + "File: app/templates/application.hbs", + "Parse error on line 4:", + " at AStackTrace", + ]) + paths = build_paths(error_file) + monitor = EmberCli::BuildMonitor.new("app-name", paths) + + expect { monitor.check! }. + to raise_error( + EmberCli::BuildError, + %{"app-name" has failed to build: Build failed.\nFile: app/templates/application.hbs\nParse error on line 4:}, + ) + end + + it "sets the backtrace to the lines of the failure" do + error_file = error_file_with_contents( + [ + "File: app/templates/application.hbs", + "Parse error on line 4:", + ]) + paths = build_paths(error_file) + monitor = EmberCli::BuildMonitor.new("app-name", paths) + + expect { monitor.check! }.to raise_error(EmberCli::BuildError) do |error| + expect(error.backtrace).to eq( + [ + "File: app/templates/application.hbs", + "Parse error on line 4:", + ]) + end + end + end + + context "when the error file's lines end in newlines" do + it "raises a BuildError without the trailing newlines" do + error_file = error_file_with_contents( + [ + "File: app/templates/application.hbs\n", + "Parse error on line 4:\n", + ]) + paths = build_paths(error_file) + monitor = EmberCli::BuildMonitor.new("app-name", paths) + + expect { monitor.check! }. + to raise_error( + EmberCli::BuildError, + %{"app-name" has failed to build: File: app/templates/application.hbs\nParse error on line 4:}, + ) + end + end + context "when the error file only contains deprecation warnings" do it "does not raise a BuildError" do error_file = error_file_with_contents(