mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
better error handling
This commit is contained in:
+17
-12
@@ -396,8 +396,6 @@ process_exec :: proc(
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
defer if err != nil { _, _ = process_wait(process) }
|
|
||||||
|
|
||||||
stdout_b: [dynamic]byte
|
stdout_b: [dynamic]byte
|
||||||
stdout_b.allocator = allocator
|
stdout_b.allocator = allocator
|
||||||
defer stdout = stdout_b[:]
|
defer stdout = stdout_b[:]
|
||||||
@@ -410,42 +408,49 @@ process_exec :: proc(
|
|||||||
n: int
|
n: int
|
||||||
|
|
||||||
stdout_done, stderr_done, has_data: bool
|
stdout_done, stderr_done, has_data: bool
|
||||||
for !stdout_done || !stderr_done {
|
for err == nil && (!stdout_done || !stderr_done) {
|
||||||
|
|
||||||
if !stdout_done {
|
if !stdout_done {
|
||||||
has_data, err = pipe_has_data(stdout_r)
|
has_data, err = pipe_has_data(stdout_r)
|
||||||
if has_data {
|
if has_data {
|
||||||
n, err = read(stdout_r, buf[:])
|
n, err = read(stdout_r, buf[:])
|
||||||
append(&stdout_b, ..buf[:n]) or_return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch err {
|
switch err {
|
||||||
case nil: // nothing
|
case nil:
|
||||||
|
_, err = append(&stdout_b, ..buf[:n])
|
||||||
case .EOF, .Broken_Pipe:
|
case .EOF, .Broken_Pipe:
|
||||||
stdout_done = true
|
stdout_done = true
|
||||||
err = nil
|
err = nil
|
||||||
case:
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !stderr_done {
|
if err == nil && !stderr_done {
|
||||||
has_data, err = pipe_has_data(stderr_r)
|
has_data, err = pipe_has_data(stderr_r)
|
||||||
if has_data {
|
if has_data {
|
||||||
n, err = read(stderr_r, buf[:])
|
n, err = read(stderr_r, buf[:])
|
||||||
append(&stderr_b, ..buf[:n]) or_return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch err {
|
switch err {
|
||||||
case nil: // nothing
|
case nil:
|
||||||
|
_, err = append(&stderr_b, ..buf[:n])
|
||||||
case .EOF, .Broken_Pipe:
|
case .EOF, .Broken_Pipe:
|
||||||
stderr_done = true
|
stderr_done = true
|
||||||
err = nil
|
err = nil
|
||||||
case:
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
state, _ = process_wait(process, timeout=0)
|
||||||
|
if !state.exited {
|
||||||
|
_ = process_kill(process)
|
||||||
|
state, _ = process_wait(process)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
state, err = process_wait(process)
|
state, err = process_wait(process)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user