Skip to content

Commit

Permalink
fix(compiler): show error on incorrect parameters
Browse files Browse the repository at this point in the history
Previously, if invalid parameters were provided to nwn_script_comp, no
error would be shown and compilation would fail silently. This change
now displays an informative message when incorrect parameters are passed.
  • Loading branch information
squattingmonk committed Mar 31, 2024
1 parent 7c4e22e commit 8c4b619
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/nasher/compile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ proc compile*(opts: Options, target: Target, updatedNss: var seq[string], exitCo

executables.keepItIf(not fileExists(it.changeFileExt("ncs")) and it notin skips)
if executables.len > 0:
warning("""
Compiled only $1 of $2 scripts. The following executable scripts do not
have matching .ncs: $3""".dedent %
warning("Compiled only $1 of $2 scripts. The following executable scripts do not have matching .ncs:\n$3" %
[$(scripts.len - executables.len), $scripts.len, executables.join(", ")])
if cmd in ["pack", "install", "serve", "test", "play"]:
let forced = getForceAnswer()
Expand Down
14 changes: 9 additions & 5 deletions src/nasher/utils/compiler.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const compilerFlags* =
# Default compiler flags; ordered referenced to `Compiler` enum above
["-y", "-lowqey"]

proc parseCompilerOutput(line: var string, compiler: Compiler): bool =
proc parseCompilerOutput(line: var string, compiler: Compiler): int =
## Intercepts the compiler's output and converts it into nasher's cli format.
case compiler:
of Organic:
Expand All @@ -30,10 +30,12 @@ proc parseCompilerOutput(line: var string, compiler: Compiler): bool =
display("Results:", matches[1])
of "E":
error("Compile Error:", "$1 :: $2" % [matches[1], matches[2].strip])
result = true
result = 1
else:
#Catchall to find other errors I didn't expect
display("Unknown Compiler Output", line)
elif line.startsWith "Usage":
result = 2
of Legacy:
var
token: string
Expand All @@ -51,7 +53,7 @@ proc parseCompilerOutput(line: var string, compiler: Compiler): bool =
var lines = line.split(':').mapIt(it.strip)
if lines.contains("Error"):
error(lines.filterIt(it != "Error").join("\n"))
result = true
result = 1
elif lines.contains("Warning"):
warning(lines.filterIt(it != "Warning").join("\n"))
else:
Expand All @@ -72,7 +74,9 @@ proc runCompiler*(cmd: string, args: openArray[string] = []): int =

while p.running:
if s.readLine(line):
if line.parseCompilerOutput(compiler):
result = 1
result = line.parseCompilerOutput(compiler)
if result == 2:
error("Error:", "Incorrect args provided to compiler: " & params.join(" "))
break

p.close

0 comments on commit 8c4b619

Please sign in to comment.