G-Research / fsharp-analyzers

Analyzers for F#
https://g-research.github.io/fsharp-analyzers/
Apache License 2.0
14 stars 1 forks source link

False positive on matching log args #69

Closed Smaug123 closed 5 months ago

Smaug123 commented 5 months ago

I observed today in GR that GRA-LOGTEMPLMISSVALS-001 incorrectly fired on the following:

log.LogWarning(e, "Error: {Something}", 3)

Since the first argument inherits from Exception, it should be ignored for the purposes of this analyzer.

dawedawe commented 5 months ago

Mmh, I can't reproduce this one with:

type MyEx () =
    inherit System.Exception()

let testlog1 () =
    use factory = LoggerFactory.Create(fun b -> b.AddConsole() |> ignore)
    let log: ILogger = factory.CreateLogger("Program")
    let e: MyEx = MyEx()
    log.LogWarning(e, "Error: {Something}", 3)

Or do you mean it should ignore missing args if the first arg inherits from exception, like:

log.LogWarning(e, "Error: {Something}") // don't warn here
Smaug123 commented 5 months ago

Oh sorry, I'll try and reproduce it internally and get an exact repro out to you.

dawedawe commented 5 months ago

Cool, thanks!

nojaf commented 5 months ago

@dawedawe sample to reproduce should be:

namespace Blah

open Microsoft.Extensions.Logging

module Program =
    [<EntryPoint>]
    let main argv =
        let log : ILogger = failwith "TODO"
        try
            failwith "no"
        with e ->
            log.LogError (e, "Failed to look up: {s_Group}", 3)
            raise e
        0