Skip to content

Commit

Permalink
Don't ignore error when loading plugin
Browse files Browse the repository at this point in the history
Fix #3441
  • Loading branch information
Maxime Mangel committed Aug 16, 2023
1 parent d6f15a5 commit d212c2f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Fable.Cli/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <target>` instead
* Fix #3441: Don't ignore error when loading plugin

### 4.1.4

Expand Down
37 changes: 27 additions & 10 deletions src/Fable.Transforms/State.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 -> ()

Expand Down

0 comments on commit d212c2f

Please sign in to comment.