Add error handling for process creation.

This commit is contained in:
Sönke Ludwig 2020-05-18 16:44:11 +02:00
parent fb27359214
commit 4344333946

View file

@ -40,7 +40,10 @@ Process adoptProcessID(Pid pid)
/// ditto /// ditto
Process adoptProcessID(int pid) Process adoptProcessID(int pid)
{ {
return Process(eventDriver.processes.adopt(pid)); auto p = eventDriver.processes.adopt(pid);
if (p == ProcessID.invalid)
throw new Exception("Failed to adopt process ID");
return Process(p);
} }
/** /**
@ -81,15 +84,19 @@ Process spawnProcess(
Config config = Config.none, Config config = Config.none,
scope NativePath workDir = NativePath.init) scope NativePath workDir = NativePath.init)
@trusted { @trusted {
return Process(eventDriver.processes.spawn( auto process = eventDriver.processes.spawn(
args, args,
ProcessStdinFile(ProcessRedirect.inherit), ProcessStdinFile(ProcessRedirect.inherit),
ProcessStdoutFile(ProcessRedirect.inherit), ProcessStdoutFile(ProcessRedirect.inherit),
ProcessStderrFile(ProcessRedirect.inherit), ProcessStderrFile(ProcessRedirect.inherit),
env, env,
config, config,
workDir.toNativeString()).pid workDir.toNativeString());
);
if (process.pid == ProcessID.invalid)
throw new Exception("Failed to spawn process");
return Process(process.pid);
} }
/// ditto /// ditto
@ -638,6 +645,9 @@ ProcessPipes pipeProcess(
config, config,
workDir.toNativeString()); workDir.toNativeString());
if (process.pid == ProcessID.invalid)
throw new Exception("Failed to spawn process");
return ProcessPipes( return ProcessPipes(
Process(process.pid), Process(process.pid),
PipeOutputStream(cast(PipeFD)process.stdin), PipeOutputStream(cast(PipeFD)process.stdin),