@@ -26,7 +26,7 @@ class CSharpRunner
26
26
/// <param name="run">Set to false to compile and cache the script without launching it</param>
27
27
/// <exception cref="CSharpException">Thrown if an error occured</exception>
28
28
/// <returns>Result of the execution, returned by the script</returns>
29
- public static object ? Run ( ChatBot apiHandler , string [ ] lines , string [ ] args , Dictionary < string , object > ? localVars , bool run = true )
29
+ public static object ? Run ( ChatBot apiHandler , string [ ] lines , string [ ] args , Dictionary < string , object > ? localVars , bool run = true , string scriptName = "Unknown Script" )
30
30
{
31
31
//Script compatibility check for handling future versions differently
32
32
if ( lines . Length < 1 || lines [ 0 ] != "//MCCScript 1.0" )
@@ -102,13 +102,24 @@ class CSharpRunner
102
102
"}}" ,
103
103
} ) ;
104
104
105
+ ConsoleIO . WriteLogLine ( $ "[Script] Starting compilation for { scriptName } ...") ;
106
+
105
107
//Compile the C# class in memory using all the currently loaded assemblies
106
108
var result = compiler . Compile ( code , Guid . NewGuid ( ) . ToString ( ) ) ;
107
109
108
110
//Process compile warnings and errors
109
- if ( result . Failures != null )
110
- throw new CSharpException ( CSErrorType . LoadError ,
111
- new InvalidOperationException ( result . Failures [ 0 ] . GetMessage ( ) ) ) ;
111
+ if ( result . Failures != null ) {
112
+
113
+ ConsoleIO . WriteLogLine ( "[Script] Compilation failed with error(s):" ) ;
114
+
115
+ foreach ( var failure in result . Failures ) {
116
+ ConsoleIO . WriteLogLine ( $ "[Script] Error in { scriptName } , line:col{ failure . Location . GetMappedLineSpan ( ) } : [{ failure . Id } ] { failure . GetMessage ( ) } ") ;
117
+ }
118
+
119
+ throw new CSharpException ( CSErrorType . InvalidScript , new InvalidProgramException ( "Compilation failed due to error." ) ) ;
120
+ }
121
+
122
+ ConsoleIO . WriteLogLine ( "[Script] Compilation done with no errors." ) ;
112
123
113
124
//Retrieve compiled assembly
114
125
assembly = result . Assembly ;
@@ -385,7 +396,7 @@ public bool SetServer(string server, bool andReconnect = false)
385
396
{
386
397
throw new CSharpException ( CSErrorType . FileReadError , e ) ;
387
398
}
388
- return CSharpRunner . Run ( this , lines , args , localVars ) ;
399
+ return CSharpRunner . Run ( this , lines , args , localVars , scriptName : script ) ;
389
400
}
390
401
}
391
402
}
0 commit comments