diff --git a/ReactiveTask/Errors.swift b/ReactiveTask/Errors.swift index 74b93de..9232f6c 100644 --- a/ReactiveTask/Errors.swift +++ b/ReactiveTask/Errors.swift @@ -12,7 +12,7 @@ import ReactiveCocoa /// An error originating from ReactiveTask. public enum TaskError: ErrorType { /// A shell task exited unsuccessfully. - case ShellTaskFailed(exitCode: Int32, standardError: String?) + case ShellTaskFailed(Task, exitCode: Int32, standardError: String?) /// An error was returned from a POSIX API. case POSIXError(Int32) @@ -21,8 +21,8 @@ public enum TaskError: ErrorType { extension TaskError: CustomStringConvertible { public var description: String { switch self { - case let .ShellTaskFailed(exitCode, standardError): - var description = "A shell task failed with exit code \(exitCode)" + case let .ShellTaskFailed(task, exitCode, standardError): + var description = "A shell task (\(task)) failed with exit code \(exitCode)" if let standardError = standardError { description += ":\n\(standardError)" } diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index e6552e5..e8fd29b 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -461,8 +461,8 @@ public func launchTask(task: Task, standardInput: SignalProducer SignalProducer, TaskError> in let errorString = (data.length > 0 ? NSString(data: data, encoding: NSUTF8StringEncoding) as? String : nil) - return SignalProducer(error: .ShellTaskFailed(exitCode: terminationStatus, standardError: errorString)) + return SignalProducer(error: .ShellTaskFailed(task, exitCode: terminationStatus, standardError: errorString)) } .start(observer) } diff --git a/ReactiveTaskTests/TaskSpec.swift b/ReactiveTaskTests/TaskSpec.swift index c133f74..9dfdf6d 100644 --- a/ReactiveTaskTests/TaskSpec.swift +++ b/ReactiveTaskTests/TaskSpec.swift @@ -80,5 +80,17 @@ class TaskSpec: QuickSpec { expect(NSString(data: data, encoding: NSUTF8StringEncoding)).to(equal("bar\nbuzz\nfoo\nfuzz\n")) } } + + it("should error correctly") { + let task = Task("/usr/bin/stat", arguments: [ "not-a-real-file" ]) + let result = launchTask(task) + .wait() + + expect(result).notTo(beNil()) + expect(result.error).toNot(beNil()) + if let error = result.error { + expect(error.description) == "A shell task (/usr/bin/stat not-a-real-file) failed with exit code 1:\nstat: not-a-real-file: stat: No such file or directory\n" + } + } } }