Use exceptions instead of quitting to get stacktrace

This commit is contained in:
Joey Yakimowich-Payne 2018-06-18 19:47:13 +09:00
commit a3d48fb1ac

View file

@ -53,10 +53,12 @@ proc execProc(cmd: string): string =
var x = p.peekExitCode() var x = p.peekExitCode()
if x != 0: if x != 0:
echo "Command failed: " & $x raise newException(
echo cmd Exception,
echo result "Command failed: " & $x &
quit(1) "\nCMD: " & $cmd &
"\nRESULT: " & $result
)
proc extractZip(zipfile: string) = proc extractZip(zipfile: string) =
var cmd = "unzip -o $#" var cmd = "unzip -o $#"
@ -129,9 +131,7 @@ proc doCopy(flist: string) =
for pair in flist.split(","): for pair in flist.split(","):
let spl = pair.split("=") let spl = pair.split("=")
if spl.len() != 2: if spl.len() != 2:
echo "Bad copy syntax: " & flist raise newException(Exception, "Bad copy syntax: " & flist)
quit(1)
let let
lfile = spl[0].strip() lfile = spl[0].strip()
rfile = spl[1].strip() rfile = spl[1].strip()
@ -193,8 +193,7 @@ proc search(file: string): string =
found = true found = true
break break
if not found: if not found:
echo "File doesn't exist: " & file raise newException(Exception, "File doesn't exist: " & file)
quit(1)
# Only keep relative directory # Only keep relative directory
result = result.replace(gProjectDir & $DirSep, "") result = result.replace(gProjectDir & $DirSep, "")
@ -306,9 +305,7 @@ proc rename(file: string, renfile: string) =
for entry in matches[1].split(","): for entry in matches[1].split(","):
let spl = entry.split("=") let spl = entry.split("=")
if spl.len() != 2: if spl.len() != 2:
echo "Bad replace syntax: " & renfile raise newException(Exception, "Bad replace syntax: " & renfile)
quit(1)
let let
srch = spl[0].strip() srch = spl[0].strip()
repl = spl[1].strip() repl = spl[1].strip()
@ -694,9 +691,7 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
c2nimConfig.ppflags = cfg[act] c2nimConfig.ppflags = cfg[act]
if c2nimConfig.recurse and c2nimConfig.inline: if c2nimConfig.recurse and c2nimConfig.inline:
echo "Cannot use recurse and inline simultaneously" raise newException(Exception, "Cannot use recurse and inline simultaneously")
quit(1)
if not noprocess: if not noprocess:
let nimFile = getNimout(sfile) let nimFile = getNimout(sfile)
c2nim(file, nimFile, c2nimConfig) c2nim(file, nimFile, c2nimConfig)
@ -705,8 +700,7 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
proc runCfg(cfg: string) = proc runCfg(cfg: string) =
if not fileExists(cfg): if not fileExists(cfg):
echo "Config doesn't exist: " & cfg raise newException(Exception, "Config doesn't exist: " & cfg)
quit(1)
gConfig = loadConfig(cfg) gConfig = loadConfig(cfg)
@ -718,15 +712,13 @@ proc runCfg(cfg: string) =
try: try:
removeDir(gOutput) removeDir(gOutput)
except OSError: except OSError:
echo "Directory in use: " & gOutput raise newException(Exception, "Directory in use: " & gOutput)
quit(1)
else: else:
for f in walkFiles(gOutput/"*.nim"): for f in walkFiles(gOutput/"*.nim"):
try: try:
removeFile(f) removeFile(f)
except OSError: except OSError:
echo "Unable to delete: " & f raise newException(Exception, "Unable to delete: " & f)
quit(1)
createDir(gOutput) createDir(gOutput)
if gConfig["n.global"].hasKey("cpp_compiler"): if gConfig["n.global"].hasKey("cpp_compiler"):