From d212c2f21ae5043a4b386ed496ad5fa0776a89d6 Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Wed, 16 Aug 2023 21:30:27 +0200 Subject: [PATCH] Don't ignore error when loading plugin Fix #3441 --- src/Fable.Cli/RELEASE_NOTES.md | 1 + src/Fable.Transforms/State.fs | 37 +++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Fable.Cli/RELEASE_NOTES.md b/src/Fable.Cli/RELEASE_NOTES.md index 03347b1427..09952bd709 100644 --- a/src/Fable.Cli/RELEASE_NOTES.md +++ b/src/Fable.Cli/RELEASE_NOTES.md @@ -8,6 +8,7 @@ * Fix #3464: Invalidate cache when the target language changes * Always delete the `fable_modules` folder when the cache is invalidated * Remove `--typescript` options support, use `--lang ` instead +* Fix #3441: Don't ignore error when loading plugin ### 4.1.4 diff --git a/src/Fable.Transforms/State.fs b/src/Fable.Transforms/State.fs index e3874a7d14..5c2e0ec7fd 100644 --- a/src/Fable.Transforms/State.fs +++ b/src/Fable.Transforms/State.fs @@ -5,6 +5,7 @@ open Fable.AST open System.Collections.Concurrent open System.Collections.Generic open FSharp.Compiler.Symbols +open System type PluginRef = { DllPath: string @@ -26,16 +27,32 @@ type Assemblies(getPlugin, fsharpAssemblies: FSharpAssembly list) = if Compiler.CoreAssemblyNames.Contains(asmName) then coreAssemblies.Add(asmName, asm) else - try - let scanForPlugins = - asm.Contents.Attributes |> Seq.exists (fun attr -> - attr.AttributeType.TryFullName = Some "Fable.ScanForPluginsAttribute") - if scanForPlugins then - for e in asm.Contents.Entities do - if e.IsAttributeType && FSharp2Fable.Util.inherits e "Fable.PluginAttribute" then - let plugin = getPlugin { DllPath = path; TypeFullName = e.FullName } - plugins.Add(FSharp2Fable.FsEnt.Ref e, plugin) - with _ -> () + let scanForPlugins = + asm.Contents.Attributes |> Seq.exists (fun attr -> + attr.AttributeType.TryFullName = Some "Fable.ScanForPluginsAttribute") + if scanForPlugins then + for e in asm.Contents.Entities do + if e.IsAttributeType && FSharp2Fable.Util.inherits e "Fable.PluginAttribute" then + try + let plugin = getPlugin { DllPath = path; TypeFullName = e.FullName } + plugins.Add(FSharp2Fable.FsEnt.Ref e, plugin) + with ex -> + let errorMessage = + [ + $"Error while loading plugin: {e.FullName}" + "" + "This error often happens if you are trying to use a plugin that is not compatible with the current version of Fable." + "" + "If you see this error please open an issue at https://github.com/fable-compiler/Fable/" + "so we can check if we can improve the plugin detection mechanism." + ] + |> String.concat "\n" + + Console.ForegroundColor <- ConsoleColor.DarkRed + Console.Error.WriteLine(errorMessage) + Console.ResetColor() + raise ex + assemblies.Add(path, asm) | None -> ()