oleg-shilo / cs-script

C# scripting platform
http://www.cs-script.net
MIT License
1.62k stars 235 forks source link

Enhance error message returned from Script Compilation in some scenarios #281

Closed TomBruns closed 2 years ago

TomBruns commented 2 years ago

In some error scenarios the Output property (instead of the Errors property) is populated on the CompilerResults object

image In these cases the library returns the less helpful "Unknown compiler error" message

Suggested chgs in Evaluator.CodeDom in Compile method at the bottom summary: if Errors is empty but Output is populated => use it,

                    if (result.Errors.IsEmpty() && result.Output.IsEmpty())
                    {
                        // unknown error; e.g. invalid compiler params
                        result.Errors.Add(new CompilerError { ErrorText = "Unknown compiler error\n" + sdk_warning });
                    }
                    else if (!result.Errors.IsEmpty())
                    { 
                        // always prefer info from Errors property
                    }
                    else if (!result.Output.IsEmpty())
                    {
                        foreach (var outputMsg in result.Output)
                        {
                            result.Errors.Add(new CompilerError { ErrorText = $"{outputMsg}\n" });
                        }
                    }

                    throw CompilerException.Create(result.Errors, true, true);
                }
oleg-shilo commented 2 years ago

Excellent suggestion. Txs. Done. I only changed your solution logic to avoid the accidental breakdown of a single error in multiple CompileError objects. Will be available in the very next release.