Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
------

Expand Down
7 changes: 4 additions & 3 deletions lib/ember_cli/build_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions spec/lib/ember_cli/build_monitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down