Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail the tool if any analysis fails #200

Merged
merged 2 commits into from
Jan 29, 2024
Merged

Conversation

Smaug123
Copy link
Contributor

@Smaug123 Smaug123 commented Jan 26, 2024

Motivation is https://github.com/Smaug123/fsharp-prattparser/actions/runs/7619221208/job/20751901249 , which succeeded despite the output being as follows:

info: Running in verbose mode
info: Treat as Hints: []
info: Treat as Info: []
info: Treat as Warning: []
info: Treat as Error: [GRA-IMMUTABLECOLLECTIONEQUALITY-001, GRA-INTERPOLATED-001, GRA-JSONOPTS-001, GRA-LOGARGFUNCFULLAPP-001, GRA-STRING-001, GRA-STRING-002, GRA-STRING-003, GRA-TYPE-ANNOTATE-001, GRA-UNIONCASE-001, GRA-VIRTUALCALL-001]
info: Exclude Files: []
info: Include Files: []
info: Loading analyzers from /home/runner/work/fsharp-prattparser/fsharp-prattparser/.analyzerpackages/g-research.fsharp.analyzers/0.7.0/
info: Registered 12 analyzers from 1 dlls
error: Checking of file /home/runner/work/fsharp-prattparser/fsharp-prattparser/PrattParser/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.fs aborted
error: Checking of file /home/runner/work/fsharp-prattparser/fsharp-prattparser/PrattParser/obj/Debug/net8.0/PrattParser.AssemblyInfo.fs aborted
error: Checking of file /home/runner/work/fsharp-prattparser/fsharp-prattparser/PrattParser/obj/Debug/net8.0/PrattParser.Version.fs aborted
error: Checking of file /home/runner/work/fsharp-prattparser/fsharp-prattparser/PrattParser/Parser.fs aborted
info: No messages found from the analyzer(s)

In order not to have a heap of primitive types like _ list option, I pulled out the failure case into a single-case DU. That way, the semantics are much clearer if you're only looking at the type signatures.

m.Code,
m.Message
)
)

()

let writeReport (results: AnalyzerMessage list option) (codeRoot: string option) (report: string) =
let writeReport (results: AnalyzerMessage list) (codeRoot: string option) (report: string) =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was never actually optional; we always statically knew that this option was Some. I tightened up the domain by representing that fact in the types.

)
|> Async.Parallel

return
Some
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was never any chance that this was None, so again I tightened up the types to get rid of the option. Instead it's now applied where it's needed (namely in the big match in Program.fs).

)
|> Array.map (fun ctx ->
logger.LogInformation("Running analyzers for {0}", ctx.FileName)
client.RunAnalyzers ctx
match ctx with
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could all have been done point-free but I thought it was clearer this way.

let mappedMessages = messages |> List.map (mapMessageToSeverity mappings)
yield! mappedMessages
]
messagesPerAnalyzer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Again, this could have been point-free.)

@@ -375,20 +384,6 @@ let writeReport (results: AnalyzerMessage list option) (codeRoot: string option)
logger.LogError(ex, "Could not write sarif to {report}", report)
logger.LogInformation("{0}", ex)

let calculateExitCode (msgs: AnalyzerMessage list option) : int =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now extracted to the bottom of the file, where the logic is inlined. That's because our exit code now depends on knowledge we only have down there, and I didn't really fancy passing more args into this function.

@@ -623,6 +618,7 @@ let main argv =
| [], Some fscArgs ->
runFscArgs client fscArgs exclInclFiles severityMapping
|> Async.RunSynchronously
|> Some
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Fallout from the "remove the spurious option type" in FSharp.Analyzers.SDK.fs)

Copy link
Contributor

@nojaf nojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from afar! I'll let @dawedawe do a proper review as he is more familiar with the latest of the CLI tool (I think).

One thing that would be great if we had some additional help text about the exit codes. On how to interpret them.

@Smaug123
Copy link
Contributor Author

Personally I'm less concerned about documenting exit codes because we already log on all these error cases.

@dawedawe
Copy link
Contributor

Personally I'm less concerned about documenting exit codes because we already log on all these error cases.

Thanks for the work. We can document the exit codes in another PR, then.

@Smaug123
Copy link
Contributor Author

Would you mind merging this please? I don't have permission to.

@dawedawe dawedawe merged commit 27780b6 into ionide:main Jan 29, 2024
2 checks passed
@nojaf
Copy link
Contributor

nojaf commented Jan 29, 2024

@Smaug123 would you like a new release with all your latest changes?

@Smaug123 Smaug123 deleted the fail-on-failure-2 branch January 29, 2024 19:29
@Smaug123
Copy link
Contributor Author

That would be great, thanks!

@nojaf
Copy link
Contributor

nojaf commented Jan 30, 2024

@Smaug123
Copy link
Contributor Author

Thanks - working perfectly (https://github.com/Smaug123/fsharp-prattparser/actions/runs/7708627409/job/21008123060?pr=2 now loudly fails rather than silently failing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants