From bd59dc4e5374d60ca3031a2650bda4f738aab21c Mon Sep 17 00:00:00 2001 From: Rachel Brindle Date: Tue, 23 Feb 2016 14:59:01 -0800 Subject: [PATCH 1/2] TaskError should report which task failed --- ReactiveTask/Errors.swift | 6 +++--- ReactiveTask/Task.swift | 6 +++--- ReactiveTaskTests/TaskSpec.swift | 12 ++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ReactiveTask/Errors.swift b/ReactiveTask/Errors.swift index 74b93de..e65b3c0 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: 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..3e978b1 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: 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" + } + } } } From 9d0b2bee491a66f2850f4b57d84fcacbc3e283ea Mon Sep 17 00:00:00 2001 From: Rachel Brindle Date: Tue, 23 Feb 2016 16:44:59 -0800 Subject: [PATCH 2/2] First argument to TaskError.ShellTaskFailed should not be named --- ReactiveTask/Errors.swift | 2 +- ReactiveTask/Task.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ReactiveTask/Errors.swift b/ReactiveTask/Errors.swift index e65b3c0..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(task: Task, exitCode: Int32, standardError: String?) + case ShellTaskFailed(Task, exitCode: Int32, standardError: String?) /// An error was returned from a POSIX API. case POSIXError(Int32) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 3e978b1..e8fd29b 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -477,7 +477,7 @@ 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(task: task, exitCode: terminationStatus, standardError: errorString)) + return SignalProducer(error: .ShellTaskFailed(task, exitCode: terminationStatus, standardError: errorString)) } .start(observer) }