Consolodate error classes.
This commit is contained in:
parent
9e80847ac7
commit
c0c422c373
@ -29,9 +29,6 @@ module Compass
|
|||||||
File.expand_path(File.join(File.dirname(__FILE__)))
|
File.expand_path(File.join(File.dirname(__FILE__)))
|
||||||
end
|
end
|
||||||
module_function :base_directory, :lib_directory
|
module_function :base_directory, :lib_directory
|
||||||
|
|
||||||
class Error < StandardError
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require File.join(File.dirname(__FILE__), 'compass', 'frameworks')
|
require File.join(File.dirname(__FILE__), 'compass', 'frameworks')
|
||||||
|
@ -13,7 +13,7 @@ module Compass
|
|||||||
if File.exists?(to) && !options[:force]
|
if File.exists?(to) && !options[:force]
|
||||||
#TODO: Detect differences & provide an overwrite prompt
|
#TODO: Detect differences & provide an overwrite prompt
|
||||||
msg = "#{basename(to)} already exists."
|
msg = "#{basename(to)} already exists."
|
||||||
raise InstallationError.new(msg)
|
raise Compass::FilesystemConflict.new(msg)
|
||||||
elsif File.exists?(to)
|
elsif File.exists?(to)
|
||||||
logger.record :overwrite, basename(to)
|
logger.record :overwrite, basename(to)
|
||||||
FileUtils.rm to unless options[:dry_run]
|
FileUtils.rm to unless options[:dry_run]
|
||||||
@ -31,7 +31,7 @@ module Compass
|
|||||||
logger.record :exists, basename(dir)
|
logger.record :exists, basename(dir)
|
||||||
elsif File.exists?(dir)
|
elsif File.exists?(dir)
|
||||||
msg = "#{basename(dir)} already exists and is not a directory."
|
msg = "#{basename(dir)} already exists and is not a directory."
|
||||||
raise InstallationError.new(msg)
|
raise Compass::FilesystemConflict.new(msg)
|
||||||
else
|
else
|
||||||
logger.record :directory, basename(dir)
|
logger.record :directory, basename(dir)
|
||||||
FileUtils.mkdir_p(dir) unless options[:dry_run]
|
FileUtils.mkdir_p(dir) unless options[:dry_run]
|
||||||
@ -43,7 +43,7 @@ module Compass
|
|||||||
options ||= self.options if self.respond_to?(:options)
|
options ||= self.options if self.respond_to?(:options)
|
||||||
if File.exists?(file_name) && !options[:force]
|
if File.exists?(file_name) && !options[:force]
|
||||||
msg = "File #{basename(file_name)} already exists. Run with --force to force creation."
|
msg = "File #{basename(file_name)} already exists. Run with --force to force creation."
|
||||||
raise InstallationError.new(msg)
|
raise Compass::FilesystemConflict.new(msg)
|
||||||
end
|
end
|
||||||
if File.exists?(file_name)
|
if File.exists?(file_name)
|
||||||
logger.record :overwrite, basename(file_name)
|
logger.record :overwrite, basename(file_name)
|
||||||
|
@ -52,9 +52,9 @@ module Compass
|
|||||||
|
|
||||||
def assert_project_directory_exists!
|
def assert_project_directory_exists!
|
||||||
if File.exists?(project_directory) && !File.directory?(project_directory)
|
if File.exists?(project_directory) && !File.directory?(project_directory)
|
||||||
raise Compass::Exec::ExecError.new("#{project_directory} is not a directory.")
|
raise Compass::FilesystemConflict.new("#{project_directory} is not a directory.")
|
||||||
elsif !File.directory?(project_directory)
|
elsif !File.directory?(project_directory)
|
||||||
raise ::Compass::Exec::ExecError.new("#{project_directory} does not exist.")
|
raise Compass::Error.new("#{project_directory} does not exist.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
7
lib/compass/errors.rb
Normal file
7
lib/compass/errors.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module Compass
|
||||||
|
class Error < StandardError
|
||||||
|
end
|
||||||
|
|
||||||
|
class FilesystemConflict < Error
|
||||||
|
end
|
||||||
|
end
|
@ -3,16 +3,11 @@ require 'rubygems'
|
|||||||
require 'haml'
|
require 'haml'
|
||||||
require File.join(Compass.lib_directory, 'compass', 'logger')
|
require File.join(Compass.lib_directory, 'compass', 'logger')
|
||||||
require File.join(Compass.lib_directory, 'compass', 'configuration')
|
require File.join(Compass.lib_directory, 'compass', 'configuration')
|
||||||
|
require File.join(Compass.lib_directory, 'compass', 'errors')
|
||||||
require File.join(Compass.lib_directory, 'compass', 'actions')
|
require File.join(Compass.lib_directory, 'compass', 'actions')
|
||||||
|
|
||||||
module Compass
|
module Compass
|
||||||
module Exec
|
module Exec
|
||||||
class ExecError < StandardError
|
|
||||||
end
|
|
||||||
|
|
||||||
class DirectoryExistsError < ExecError
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def report_error(e, options)
|
def report_error(e, options)
|
||||||
$stderr.puts "#{e.class} on line #{get_line e} of #{get_file e}: #{e.message}"
|
$stderr.puts "#{e.class} on line #{get_line e} of #{get_file e}: #{e.message}"
|
||||||
@ -51,7 +46,7 @@ module Compass
|
|||||||
perform!
|
perform!
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
raise e if e.is_a? SystemExit
|
raise e if e.is_a? SystemExit
|
||||||
if e.is_a?(ExecError) || e.is_a?(OptionParser::ParseError)
|
if e.is_a?(::Compass::Error) || e.is_a?(OptionParser::ParseError)
|
||||||
$stderr.puts e.message
|
$stderr.puts e.message
|
||||||
else
|
else
|
||||||
::Compass::Exec.report_error(e, @options)
|
::Compass::Exec.report_error(e, @options)
|
||||||
|
@ -1,15 +1,3 @@
|
|||||||
module Compass
|
|
||||||
module Installers
|
|
||||||
|
|
||||||
class InstallationError < Compass::Error
|
|
||||||
end
|
|
||||||
|
|
||||||
class DirectoryExistsError < InstallationError
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
require File.join(File.dirname(__FILE__), 'installers', 'manifest')
|
require File.join(File.dirname(__FILE__), 'installers', 'manifest')
|
||||||
require File.join(File.dirname(__FILE__), 'installers', 'base')
|
require File.join(File.dirname(__FILE__), 'installers', 'base')
|
||||||
require File.join(File.dirname(__FILE__), 'installers', 'stand_alone')
|
require File.join(File.dirname(__FILE__), 'installers', 'stand_alone')
|
||||||
|
Loading…
Reference in New Issue
Block a user