Skip to content

Commit

Permalink
Merge pull request #16 from p-x9/feature/throw-script-error
Browse files Browse the repository at this point in the history
If scrips terminate with an error, raise a build warning
  • Loading branch information
p-x9 committed Aug 25, 2023
2 parents 83f03f9 + 95a0898 commit 116adc5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Sources/run-script/main.swift
Expand Up @@ -85,8 +85,10 @@ extension RunScript {
extension RunScript {
func run(_ script: Script) throws {
let process = Process()
let errorPipe = Pipe()

process.launchPath = script.launchPath ?? "/bin/sh"
process.standardError = errorPipe

if let path = script.path {
process.arguments = [path]
Expand All @@ -96,8 +98,12 @@ extension RunScript {
process.arguments = ["-c", script]
}

process.launch()
process.waitUntilExit()
try process.run()

let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()
if let error = String(data: errorData, encoding: .utf8) {
log("warning: [RunScriptPlugin] " + error)
}
}
}

Expand Down

0 comments on commit 116adc5

Please sign in to comment.