Skip to content

Commit

Permalink
Raise BuildError when EmberCLI app fails to build
Browse files Browse the repository at this point in the history
Fix #23
  • Loading branch information
rwz committed Jan 20, 2015
1 parent 0edf718 commit 2b4637b
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion lib/ember-cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class App
ADDON_VERSION = "0.0.9"
EMBER_CLI_VERSION = "~> 0.1.5"

class BuildError < StandardError; end

attr_reader :name, :options, :pid

def initialize(name, options={})
Expand All @@ -14,6 +16,7 @@ def initialize(name, options={})
def compile
prepare
silence_stream(STDOUT){ exec command }
check_for_build_error!
end

def install_dependencies
Expand Down Expand Up @@ -42,7 +45,7 @@ def exposed_css_assets

def wait
Timeout.timeout(build_timeout) do
sleep 0.1 while lockfile.exist?
wait_for_build_complete_or_error
end
rescue Timeout::Error
suggested_timeout = build_timeout + 5
Expand Down Expand Up @@ -93,10 +96,33 @@ def lockfile
tmp_path.join("build.lock")
end

def check_for_build_error!
raise_build_error! if build_error_file.exist?
end

def build_error_file
tmp_path.join("error.txt")
end

def reset_build_error!
build_error_file.delete if build_error?
end

def build_error?
build_error_file.exist?
end

def raise_build_error!
error = BuildError.new("EmberCLI app #{name.inspect} has failed to build")
error.set_backtrace build_error_file.read.split(?\n)
fail error
end

def prepare
@prepared ||= begin
check_addon!
check_ember_cli_version!
reset_build_error!
FileUtils.touch lockfile
symlink_to_assets_root
add_assets_to_precompile_list
Expand Down Expand Up @@ -219,5 +245,13 @@ def exec(cmd, options={})
Kernel.public_send(method_name, env_hash, cmd, err: :out)
end
end

def wait_for_build_complete_or_error
loop do
check_for_build_error!
break unless lockfile.exist?
sleep 0.1
end
end
end
end

1 comment on commit 2b4637b

@josemarluedke
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.