Skip to content

Commit 8756ff5

Browse files
authored
[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
1 parent 4919db8 commit 8756ff5

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

.github/workflows/build-and-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ jobs:
200200
runs-on: ubuntu-latest
201201
strategy:
202202
fail-fast: true
203-
if: ${{ !contains(github.event.head_commit.message, 'skip')}}
203+
if: ${{ !contains(github.event.head_commit.message, 'skip') || !contains(github.event.head_commit.message, 'skipci')}}
204204
steps:
205205
- name: dummy action
206206
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'"

MinecraftClient/CommandHandler/CmdResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public enum Status
2222
public CmdResult()
2323
{
2424
this.status = Status.NotRun;
25-
this.result = null;
25+
this.result = "Command did not run, cannot determine the result of the command.";
2626
}
2727

2828
public Status status;
@@ -35,7 +35,7 @@ public int SetAndReturn(Status status)
3535
this.result = status switch
3636
{
3737
#pragma warning disable format // @formatter:off
38-
Status.NotRun => null,
38+
Status.NotRun => "Command did not run, cannot determine the result of the command.",
3939
Status.FailChunkNotLoad => null,
4040
Status.FailNeedEntity => Translations.extra_entity_required,
4141
Status.FailNeedInventory => Translations.extra_inventory_required,

MinecraftClient/Scripting/CSharpRunner.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,15 @@ class CSharpRunner
116116

117117
foreach (var failure in result.Failures)
118118
{
119-
ConsoleIO.WriteLogLine($"[Script] Error in {scriptName}, line:col{failure.Location.GetMappedLineSpan()}: [{failure.Id}] {failure.GetMessage()}");
119+
// Get the line that contains the error:
120+
121+
var loc = failure.Location.GetMappedLineSpan();
122+
var line = code.Split('\n')[loc.StartLinePosition.Line];
123+
124+
ConsoleIO.WriteLogLine($"[Script] Error in {scriptName}, on line ({line.Trim()}): [{failure.Id}] {failure.GetMessage()}");
120125
}
121126

122-
throw new CSharpException(CSErrorType.InvalidScript, new InvalidProgramException("Compilation failed due to error."));
127+
throw new CSharpException(CSErrorType.InvalidScript, new InvalidProgramException("Compilation failed due to error(s)."));
123128
}
124129

125130
ConsoleIO.WriteLogLine("[Script] Compilation done with no errors.");
@@ -182,8 +187,7 @@ public class CSharpException : Exception
182187
public CSErrorType ExceptionType { get { return _type; } }
183188
public override string Message { get { return InnerException!.Message; } }
184189
public override string ToString() { return InnerException!.ToString(); }
185-
public CSharpException(CSErrorType type, Exception inner)
186-
: base(inner != null ? inner.Message : "", inner)
190+
public CSharpException(CSErrorType type, Exception inner) : base(inner.Message, inner)
187191
{
188192
_type = type;
189193
}

0 commit comments

Comments
 (0)