From 8756ff5b3cfa0ea1d9a8d9e4ba47c0b915018b5d Mon Sep 17 00:00:00 2001 From: breadbyte <14045257+breadbyte@users.noreply.github.com> Date: Sat, 22 Jun 2024 06:40:23 +0800 Subject: [PATCH] [skip ci] Miscellaneous scripting QoL improvements and fixes (#2740) * Update CI to detect the word "skipci" * Make script compilation errors more verbose Rather than just giving the line in which the error has been found, return the actual text content of the line itself * Attempt to bubble up errors in the script chain, so it says the reason for any NotRun errors. The exception message gets eaten up when the script is running, and an exception happens. Also put in a default result message for the CmdResult, instead of having it default to null. * Trim the whitespace off returned script compilation error line --- .github/workflows/build-and-release.yml | 2 +- MinecraftClient/CommandHandler/CmdResult.cs | 4 ++-- MinecraftClient/Scripting/CSharpRunner.cs | 12 ++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index d1829a8c..8c3f8865 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -200,7 +200,7 @@ jobs: runs-on: ubuntu-latest strategy: fail-fast: true - if: ${{ !contains(github.event.head_commit.message, 'skip')}} + if: ${{ !contains(github.event.head_commit.message, 'skip') || !contains(github.event.head_commit.message, 'skipci')}} steps: - name: dummy action run: "echo 'dummy action that checks if the build is to be skipped, if it is, this action does not run to break the entire build action'" diff --git a/MinecraftClient/CommandHandler/CmdResult.cs b/MinecraftClient/CommandHandler/CmdResult.cs index 4be40a4a..8ecafc8a 100644 --- a/MinecraftClient/CommandHandler/CmdResult.cs +++ b/MinecraftClient/CommandHandler/CmdResult.cs @@ -22,7 +22,7 @@ namespace MinecraftClient.CommandHandler public CmdResult() { this.status = Status.NotRun; - this.result = null; + this.result = "Command did not run, cannot determine the result of the command."; } public Status status; @@ -35,7 +35,7 @@ namespace MinecraftClient.CommandHandler this.result = status switch { #pragma warning disable format // @formatter:off - Status.NotRun => null, + Status.NotRun => "Command did not run, cannot determine the result of the command.", Status.FailChunkNotLoad => null, Status.FailNeedEntity => Translations.extra_entity_required, Status.FailNeedInventory => Translations.extra_inventory_required, diff --git a/MinecraftClient/Scripting/CSharpRunner.cs b/MinecraftClient/Scripting/CSharpRunner.cs index 1792dd5c..7f6c6e77 100644 --- a/MinecraftClient/Scripting/CSharpRunner.cs +++ b/MinecraftClient/Scripting/CSharpRunner.cs @@ -116,10 +116,15 @@ namespace MinecraftClient.Scripting foreach (var failure in result.Failures) { - ConsoleIO.WriteLogLine($"[Script] Error in {scriptName}, line:col{failure.Location.GetMappedLineSpan()}: [{failure.Id}] {failure.GetMessage()}"); + // Get the line that contains the error: + + var loc = failure.Location.GetMappedLineSpan(); + var line = code.Split('\n')[loc.StartLinePosition.Line]; + + ConsoleIO.WriteLogLine($"[Script] Error in {scriptName}, on line ({line.Trim()}): [{failure.Id}] {failure.GetMessage()}"); } - throw new CSharpException(CSErrorType.InvalidScript, new InvalidProgramException("Compilation failed due to error.")); + throw new CSharpException(CSErrorType.InvalidScript, new InvalidProgramException("Compilation failed due to error(s).")); } ConsoleIO.WriteLogLine("[Script] Compilation done with no errors."); @@ -182,8 +187,7 @@ namespace MinecraftClient.Scripting public CSErrorType ExceptionType { get { return _type; } } public override string Message { get { return InnerException!.Message; } } public override string ToString() { return InnerException!.ToString(); } - public CSharpException(CSErrorType type, Exception inner) - : base(inner != null ? inner.Message : "", inner) + public CSharpException(CSErrorType type, Exception inner) : base(inner.Message, inner) { _type = type; }