From 602ee0d5a1b092faf8f29cac0727a28640aac0b0 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 23 May 2018 11:27:56 -0400 Subject: [PATCH] Better exception output --- Makefile | 3 ++- dispatch.go | 2 +- main.go | 3 ++- util.go | 8 ++++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6139307814..fca2bc6467 100644 --- a/Makefile +++ b/Makefile @@ -14,11 +14,12 @@ TS_FILES = \ GO_FILES = \ assets.go \ deno_dir.go \ + deno_dir_test.go \ dispatch.go \ main.go \ - main_test.go \ msg.pb.go \ os.go \ + os_test.go \ timers.go \ util.go diff --git a/dispatch.go b/dispatch.go index 09e5bad9f2..33b1fdca9a 100644 --- a/dispatch.go +++ b/dispatch.go @@ -73,7 +73,7 @@ func DispatchLoop() { case msg := <-resChan: out, err := proto.Marshal(msg) err = worker.SendBytes(out) - check(err) + exitOnError(err) case <-doneChan: // All goroutines have completed. Now we can exit main(). return diff --git a/main.go b/main.go index 32f011e917..7c6fdfbd03 100644 --- a/main.go +++ b/main.go @@ -52,7 +52,8 @@ func main() { InitTimers() main_js := stringAsset("main.js") - check(worker.Load("/main.js", main_js)) + err := worker.Load("/main.js", main_js) + exitOnError(err) main_map := stringAsset("main.map") cwd, err := os.Getwd() diff --git a/util.go b/util.go index 3e0ac63746..9fab27238c 100644 --- a/util.go +++ b/util.go @@ -2,6 +2,7 @@ package main import ( "net/url" + "os" ) func assert(cond bool, msg string) { @@ -21,3 +22,10 @@ func check(e error) { panic(e) } } + +func exitOnError(err error) { + if err != nil { + os.Stderr.WriteString(err.Error()) + os.Exit(1) + } +}