diff --git a/CHANGELOG.md b/CHANGELOG.md index d53d8fb..a58dc24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ BUG FIXES: - Fix various issues related to detecting whether the container is running and is "SSHable" [#142](https://github.com/fgrehm/vagrant-lxc/issues/142) + - Nicely handle missing templates path [#139](https://github.com/fgrehm/vagrant-lxc/issues/139) ## [0.6.0](https://github.com/fgrehm/vagrant-lxc/compare/v0.5.0...v0.6.0) (Sep 12, 2013) diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index 6f9b141..67fc3c9 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -156,7 +156,9 @@ module Vagrant yield template_name ensure @logger.info 'Removing LXC template' - @sudo_wrapper.run('rm', tmp_template_path) + if tmp_template_path + @sudo_wrapper.run('rm', tmp_template_path) + end end TEMPLATES_PATH_LOOKUP = %w( @@ -169,8 +171,9 @@ module Vagrant return @templates_path if @templates_path path = TEMPLATES_PATH_LOOKUP.find { |candidate| File.directory?(candidate) } - # TODO: Raise an user friendly error - raise 'Unable to identify lxc templates path!' unless path + if !path + raise Errors::TemplatesDirMissing.new paths: TEMPLATES_PATH_LOOKUP.inspect + end @templates_path = Pathname(path) end diff --git a/lib/vagrant-lxc/errors.rb b/lib/vagrant-lxc/errors.rb index c920465..e2c612f 100644 --- a/lib/vagrant-lxc/errors.rb +++ b/lib/vagrant-lxc/errors.rb @@ -15,6 +15,9 @@ module Vagrant class TemplateFileMissing < Vagrant::Errors::VagrantError error_key(:lxc_template_file_missing) end + class TemplatesDirMissing < Vagrant::Errors::VagrantError + error_key(:lxc_templates_dir_missing) + end class RootFSTarballMissing < Vagrant::Errors::VagrantError error_key(:lxc_invalid_box_version) end diff --git a/locales/en.yml b/locales/en.yml index 5e82009..237881b 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -46,6 +46,11 @@ en: The template file used for creating the container was not found for %{name} box. + lxc_templates_dir_missing: |- + Unable to identify lxc templates path. + + Looked up under: %{paths} + lxc_not_installed: |- The `lxc` package does not seem to be installed or is not accessible on the PATH.