@@ -270,89 +270,12 @@ private func createPipe() throws -> (readEnd: FileDescriptor, writeEnd: FileDesc
270270
271271extension PipeConfiguration {
272272 public func run( ) async throws -> CollectedResult < Output , Error > {
273- if stages. count == 1 {
274- let stage = stages [ 0 ]
275-
276- switch stage. stageType {
277- case . process( let configuration, let options) :
278- // Single process - run directly with error redirection
279- switch options. errorRedirection {
280- case . separate:
281- // No redirection - use original configuration
282- return try await Subprocess . run (
283- configuration,
284- input: self . input,
285- output: self . output,
286- error: self . error
287- )
288- case . mergeWithStdout:
289- // Redirect stderr to stdout, merge both streams
290- let finalResult = try await Subprocess . run (
291- configuration,
292- input: self . input,
293- output: self . output,
294- error: . combineWithOutput
295- )
296-
297- let emptyError : Error . OutputType =
298- if Error . OutputType. self == Void . self {
299- ( ) as! Error. OutputType
300- } else if Error. OutputType. self == String ? . self {
301- String ? . none as! Error . OutputType
302- } else if Error . OutputType. self == [ UInt8] ? . self {
303- [ UInt8] ? . none as! Error . OutputType
304- } else {
305- fatalError ( )
306- }
307-
308- // Merge the different kinds of output types (string, fd, etc.)
309- if Output . OutputType. self == Void . self {
310- return CollectedResult < Output , Error > (
311- processIdentifier: finalResult. processIdentifier,
312- terminationStatus: finalResult. terminationStatus,
313- standardOutput: ( ) as! Output . OutputType ,
314- standardError: finalResult. standardOutput as! Error . OutputType
315- )
316- } else if Output . OutputType. self == String ? . self {
317- let out : String ? = finalResult. standardOutput as! String ?
318- let err : String ? = finalResult. standardError as! String ?
319-
320- let finalOutput = ( out ?? " " ) + ( err ?? " " )
321- // FIXME reduce the final output to the output.maxSize number of bytes
322-
323- return CollectedResult < Output , Error > (
324- processIdentifier: finalResult. processIdentifier,
325- terminationStatus: finalResult. terminationStatus,
326- standardOutput: finalOutput as! Output . OutputType ,
327- standardError: emptyError
328- )
329- } else if Output . OutputType. self == [ UInt8 ] . self {
330- let out : [ UInt8 ] ? = finalResult. standardOutput as! [ UInt8 ] ?
331- let err : [ UInt8 ] ? = finalResult. standardError as! [ UInt8 ] ?
332-
333- var finalOutput = ( out ?? [ ] ) + ( err ?? [ ] )
334- if finalOutput. count > self . output. maxSize {
335- finalOutput = [ UInt8] ( finalOutput [ ... self . output. maxSize] )
336- }
337-
338- return CollectedResult < Output , Error > (
339- processIdentifier: finalResult. processIdentifier,
340- terminationStatus: finalResult. terminationStatus,
341- standardOutput: finalOutput as! Output . OutputType ,
342- standardError: emptyError
343- )
344- } else {
345- fatalError ( )
346- }
347- }
348-
349- case . swiftFunction:
350- fatalError ( " Trivial pipeline with only a single swift function isn't supported " )
351- }
352- } else {
353- // Pipeline - run with task group
354- return try await runPipeline ( )
273+ guard stages. count > 1 else {
274+ fatalError ( " Trivial pipeline with only a single stage isn't supported " )
355275 }
276+
277+ // Pipeline - run with task group
278+ return try await runPipeline ( )
356279 }
357280
358281 enum CollectedPipeResult {
0 commit comments