Skip to content

Commit

Permalink
Error handling for uninstalled plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
raulssorban committed Oct 11, 2023
1 parent 71e5983 commit 295aacc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Components/Carbon.Modules
Submodule Carbon.Modules updated 0 files
9 changes: 7 additions & 2 deletions Carbon.Core/Carbon/src/Jobs/ScriptCompilationThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ public override void Start()

public override void ThreadFunction()
{
if (Sources.TrueForAll(x => string.IsNullOrEmpty(x.Content)))
{
return;
}

try
{
Exceptions.Clear();
Expand Down Expand Up @@ -343,7 +348,7 @@ public override void ThreadFunction()
var parseOptions = new CSharpParseOptions(LanguageVersion.Latest)
.WithPreprocessorSymbols(conditionals);

var containsInternalCallHookOverride = Sources.Any(x => x.Content.Contains(_internalCallHookPattern));
var containsInternalCallHookOverride = Sources.Any(x => !string.IsNullOrEmpty(x.Content) && x.Content.Contains(_internalCallHookPattern));

foreach (var source in Sources)
{
Expand Down Expand Up @@ -505,7 +510,7 @@ public override void ThreadFunction()

public override void Dispose()
{
ClassList.Clear();
ClassList?.Clear();

Exceptions?.Clear();
Warnings?.Clear();
Expand Down
49 changes: 26 additions & 23 deletions Carbon.Core/Carbon/src/Loaders/ScriptLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,34 +302,37 @@ public IEnumerator Compile()

if (AsyncLoader.Assembly == null)
{
Logger.Error($"Failed compiling '{AsyncLoader.InitialSource.ContextFilePath}':");
for (int i = 0; i < AsyncLoader.Exceptions.Count; i++)
if (AsyncLoader.Exceptions.Count > 0)
{
var error = AsyncLoader.Exceptions[i];
var print = $"{error.Error.ErrorText} [{error.Error.ErrorNumber}]\n ({error.Error.FileName} {error.Error.Column} line {error.Error.Line})";
Logger.Error($" {i + 1:n0}. {print}");
}
Logger.Error($"Failed compiling '{AsyncLoader.InitialSource.ContextFilePath}':");
for (int i = 0; i < AsyncLoader.Exceptions.Count; i++)
{
var error = AsyncLoader.Exceptions[i];
var print = $"{error.Error.ErrorText} [{error.Error.ErrorNumber}]\n ({error.Error.FileName} {error.Error.Column} line {error.Error.Line})";
Logger.Error($" {i + 1:n0}. {print}");
}

ModLoader.FailedMods.Add(new ModLoader.FailedMod
{
File = InitialSource.ContextFilePath,
Errors = AsyncLoader.Exceptions.Select(x => new ModLoader.FailedMod.Error
ModLoader.FailedMods.Add(new ModLoader.FailedMod
{
Message = x.Error.ErrorText,
Number = x.Error.ErrorNumber,
Column = x.Error.Column,
Line = x.Error.Line
}).ToArray(),
File = InitialSource.ContextFilePath,
Errors = AsyncLoader.Exceptions.Select(x => new ModLoader.FailedMod.Error
{
Message = x.Error.ErrorText,
Number = x.Error.ErrorNumber,
Column = x.Error.Column,
Line = x.Error.Line
}).ToArray(),
#if DEBUG
Warnings = AsyncLoader.Warnings.Select(x => new ModLoader.FailedMod.Error
{
Message = x.Error.ErrorText,
Number = x.Error.ErrorNumber,
Column = x.Error.Column,
Line = x.Error.Line
}).ToArray()
Warnings = AsyncLoader.Warnings.Select(x => new ModLoader.FailedMod.Error
{
Message = x.Error.ErrorText,
Number = x.Error.ErrorNumber,
Column = x.Error.Column,
Line = x.Error.Line
}).ToArray()
#endif
});
});
}

AsyncLoader.Exceptions.Clear();
AsyncLoader.Warnings.Clear();
Expand Down

0 comments on commit 295aacc

Please sign in to comment.