From f6e09ebb6aea1270431f772a644cf3042a427ccf Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Mon, 13 Mar 2023 22:52:59 +0100 Subject: [PATCH] Fixed server to return proper error messages --- config.nims | 2 +- flake.nix | 2 +- server/server.nim | 21 ++++++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/config.nims b/config.nims index d35a93d..08448f8 100644 --- a/config.nims +++ b/config.nims @@ -72,7 +72,7 @@ task clean, "Remove all generated files": task server, "Compile server daemon": --d:release - --d:yamlScalarRepInd + --stackTrace setCommand "c", "server/server" task testSuiteEvents, "Compile the testSuiteEvents tool": diff --git a/flake.nix b/flake.nix index bffc53c..a0600c7 100644 --- a/flake.nix +++ b/flake.nix @@ -94,7 +94,7 @@ proc shareDir*(): string = result = "$out/share" EOF - ${pkgs.nim}/bin/nim c --d:release --d:yamlScalarRepInd -p:"${nim-jester}/lib" -p:"${nim-httpbeast}/lib" -p:"${nim-cligen}/lib" --nimcache:.cache server/server + ${pkgs.nim}/bin/nim c --d:release --stackTrace -p:"${nim-jester}/lib" -p:"${nim-httpbeast}/lib" -p:"${nim-cligen}/lib" --nimcache:.cache server/server ''; installPhase = '' mkdir -p $out/{bin,share} diff --git a/server/server.nim b/server/server.nim index caf14e0..4b958fc 100644 --- a/server/server.nim +++ b/server/server.nim @@ -28,15 +28,18 @@ router nyRouter: of "json": style = psJson of "block": style = psBlockOnly of "tokens": - var - output = "+STR\n" - parser = initYamlParser(false) - events = parser.parse(newStringStream(@"input")) - for event in events: output.add(parser.display(event) & "\n") - output &= "-STR" - resultNode["code"] = %0 - resultNode["output"] = %output - msg = resultNode.pretty + try: + var + output = "+STR\n" + parser = initYamlParser(false) + events = parser.parse(newStringStream(@"input")) + for event in events: output.add(parser.display(event) & "\n") + output &= "-STR" + resultNode["code"] = %0 + resultNode["output"] = %output + msg = resultNode.pretty + except YamlStreamError as e: + raise e.parent else: retStatus = Http400 msg = "Invalid style: " & escape(@"style")