about summary refs log tree commit diff stats
path: root/src/ips
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-05-14 13:25:36 +0200
committerbptato <nincsnevem662@gmail.com>2023-05-14 13:25:36 +0200
commit58dee598d30c5d107f9c469eb01c660b39832f9a (patch)
tree3529a5b3499b33ad92ae394c22ad7782cf6fb7c1 /src/ips
parent938bb0d0edd2a688e4ab9ca775b2d30ffb907d72 (diff)
downloadchawan-58dee598d30c5d107f9c469eb01c660b39832f9a.tar.gz
Async resource loading, exception handling fixes
Diffstat (limited to 'src/ips')
-rw-r--r--src/ips/forkserver.nim24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/ips/forkserver.nim b/src/ips/forkserver.nim
index 5cfc7c9a..009c5491 100644
--- a/src/ips/forkserver.nim
+++ b/src/ips/forkserver.nim
@@ -69,8 +69,15 @@ proc forkLoader(ctx: var ForkServerContext, config: LoaderConfig): Pid =
     ctx.children.setLen(0)
     zeroMem(addr ctx, sizeof(ctx))
     discard close(pipefd[0]) # close read
-    runFileLoader(pipefd[1], config)
-    assert false
+    try:
+      runFileLoader(pipefd[1], config)
+    except CatchableError:
+      let e = getCurrentException()
+      # taken from system/excpt.nim
+      let msg = e.getStackTrace() & "Error: unhandled exception: " & e.msg &
+        " [" & $e.name & "]"
+      eprint(msg)
+    doAssert false
   let readfd = pipefd[0] # get read
   discard close(pipefd[1]) # close write
   var readf: File
@@ -108,8 +115,15 @@ proc forkBuffer(ctx: var ForkServerContext): Pid =
     discard close(stdin.getFileHandle())
     discard close(stdout.getFileHandle())
     let loader = FileLoader(process: loaderPid)
-    launchBuffer(config, source, attrs, loader, mainproc)
-    assert false
+    try:
+      launchBuffer(config, source, attrs, loader, mainproc)
+    except CatchableError:
+      let e = getCurrentException()
+      # taken from system/excpt.nim
+      let msg = e.getStackTrace() & "Error: unhandled exception: " & e.msg &
+        " [" & $e.name & "]"
+      eprint(msg)
+    doAssert false
   ctx.children.add((pid, loaderPid))
   return pid
 
@@ -187,7 +201,7 @@ proc newForkServer*(): ForkServer =
     discard close(pipefd_out[1])
     discard close(pipefd_err[1])
     runForkServer()
-    assert false
+    doAssert false
   else:
     discard close(pipefd_in[0]) # close read
     discard close(pipefd_out[1]) # close write