From 434433394638cfc8d5d77fddedb0534bba5c4551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 18 May 2020 16:44:11 +0200 Subject: [PATCH] Add error handling for process creation. --- source/vibe/core/process.d | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/source/vibe/core/process.d b/source/vibe/core/process.d index 1d8db70..b963933 100644 --- a/source/vibe/core/process.d +++ b/source/vibe/core/process.d @@ -40,7 +40,10 @@ Process adoptProcessID(Pid pid) /// ditto 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, scope NativePath workDir = NativePath.init) @trusted { - return Process(eventDriver.processes.spawn( + auto process = eventDriver.processes.spawn( args, ProcessStdinFile(ProcessRedirect.inherit), ProcessStdoutFile(ProcessRedirect.inherit), ProcessStderrFile(ProcessRedirect.inherit), env, config, - workDir.toNativeString()).pid - ); + workDir.toNativeString()); + + if (process.pid == ProcessID.invalid) + throw new Exception("Failed to spawn process"); + + return Process(process.pid); } /// ditto @@ -638,6 +645,9 @@ ProcessPipes pipeProcess( config, workDir.toNativeString()); + if (process.pid == ProcessID.invalid) + throw new Exception("Failed to spawn process"); + return ProcessPipes( Process(process.pid), PipeOutputStream(cast(PipeFD)process.stdin),