Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/FSharp.Analyzers.Cli/CustomLogging.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type CustomFormatter(options: IOptionsMonitor<CustomOptions>) as this =
else
this.WritePrefix(textWriter, logEntry.LogLevel)
textWriter.WriteLine(message)
// logEntry.Formatter doesn't actually write the exception so we need to do that ourselves
// https://github.com/dotnet/runtime/blob/2bcadad3045934b54672e626bbb6131f7d0a523c/src/libraries/Microsoft.Extensions.Logging.Console/src/SystemdConsoleFormatter.cs#L95-L101
if not (isNull logEntry.Exception) then
textWriter.WriteLine(logEntry.Exception.ToString())

member private x.WritePrefix(textWriter: TextWriter, logLevel: LogLevel) =
if not (isNull formatterOptions.TimestampFormat) then
Expand Down
14 changes: 14 additions & 0 deletions src/FSharp.Analyzers.Cli/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ExitErrorCodes =
| ProjectAndFscArgs = 19
| InvalidScriptArguments = 20
| InvalidProjectArguments = 21
| UnhandledException = 22

type Arguments =
| Project of string list
Expand Down Expand Up @@ -596,6 +597,19 @@ let main argv =

logger.LogInformation("Running in verbose mode")

AppDomain.CurrentDomain.UnhandledException.Add(fun args ->
let ex = args.ExceptionObject :?> exn

match ex with
| :? FileNotFoundException as fnf when fnf.FileName.StartsWith "System.Runtime" ->
// https://github.com/ionide/FSharp.Analyzers.SDK/issues/245
logger.LogCritical(ex, "FSharp.Analyzers.Cli could not find {0}. If you're using a preview version of the .NET SDK, you may need to set DOTNET_ROLL_FORWARD_TO_PRERELEASE=1 in your environment before running this tool.", fnf.FileName)
| _ ->
logger.LogCritical(ex, "Unhandled exception:")
factory.Dispose() // Flush any logs https://github.com/dotnet/extensions/issues/2395
exit (int ExitErrorCodes.UnhandledException)
)

let severityMapping =
{
TreatAsHint = results.GetResult(<@ Treat_As_Hint @>, []) |> Set.ofList
Expand Down