lib/milton.rb in citrusbyte-milton-0.3.2 vs lib/milton.rb in citrusbyte-milton-0.3.3

- old
+ new

@@ -3,10 +3,11 @@ require 'milton/core/file' module Milton # Raised when a file which was expected to exist appears not to exist class MissingFileError < StandardError;end; + class SyscallFailedError < RuntimeError;end; # Some definitions for file semantics used throughout Milton, understanding # this will make understanding the code a bit easier and avoid ambiguity: # # path: @@ -70,14 +71,28 @@ # Executes the given command, returning the commands output if successful # or false if the command failed. # Redirects stderr to log/milton.stderr.log in order to examine causes of # failure. def syscall(command) + begin + syscall!(command) + rescue Milton::SyscallFailedError => e + return false + end + end + module_function :syscall + + def syscall!(command) log("executing #{command}", invoker = Milton.called_by) stdout = %x{#{command} 2>>#{File.join(Rails.root, 'log', 'milton.stderr.log')}} - $?.success? ? stdout : (log("failed to execute #{command}", invoker) and return false) + unless $?.success? + e = Milton::SyscallFailedError.new(command) + log("failed to execute " + e.message, invoker) + raise e + end + stdout end - module_function :syscall + module_function :syscall! # Wraps +require+ on the given path in a rescue which uses the given # message for the resulting LoadError on failure instead of the default # one to give the user a better idea of what happened (useful for # dynamic +require+)