[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
This commit is contained in:
breadbyte 2024-06-22 06:40:23 +08:00 committed by GitHub
parent 4919db8820
commit 8756ff5b3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View file

@ -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,

View file

@ -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;
}