From 69aaa8725362b04eebe1ae1ddf57f3c9cd4d7a6d Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 29 Jan 2019 21:45:19 -0800 Subject: [PATCH] `quit => doAssert` to show backtrace + relevant context + exception friendly (#85) --- nimterop/git.nim | 6 ++---- nimterop/lisp.nim | 9 +++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/nimterop/git.nim b/nimterop/git.nim index edd2156..2315204 100644 --- a/nimterop/git.nim +++ b/nimterop/git.nim @@ -19,10 +19,8 @@ proc execAction*(cmd: string, nostderr=false): string = else: (result, ret) = execCmdEx(ccmd) if ret != 0: - echo "Command failed: " & $ret - echo ccmd - echo result - quit(1) + let msg = "Command failed: " & $ret & "\nccmd: " & ccmd & "\nresult:\n" & result + doAssert false, msg proc extractZip*(zipfile, outdir: string) = var cmd = "unzip -o $#" diff --git a/nimterop/lisp.nim b/nimterop/lisp.nim index c21c3be..119de36 100644 --- a/nimterop/lisp.nim +++ b/nimterop/lisp.nim @@ -25,13 +25,11 @@ proc tokenize(tree: string) = proc readFromTokens(): ref Ast = if idx == gTokens.len: - echo "Bad AST" - quit(1) + doAssert false, "Bad AST " & $(idx: idx) if gTokens[idx] == "(": if gTokens.len - idx < 2: - echo "Corrupt AST" - quit(1) + doAssert false, "Corrupt AST " & $(gTokensLen: gTokens.len, idx: idx) if gTokens[idx+1] != "comment": result = new(Ast) (result.name, result.kind, result.recursive) = gTokens[idx+1].getNameKind() @@ -44,8 +42,7 @@ proc readFromTokens(): ref Ast = if not res.isNil(): result.children.add(res) elif gTokens[idx] == ")": - echo "Poor AST" - quit(1) + doAssert false, "Poor AST " & $(idx: idx) idx += 1