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

Failing to format file should return an exit code different than 0 #1340

Closed
knocte opened this issue Dec 28, 2020 · 3 comments · Fixed by #1376
Closed

Failing to format file should return an exit code different than 0 #1340

knocte opened this issue Dec 28, 2020 · 3 comments · Fixed by #1376
Labels
clitool Area command line tool

Comments

@knocte
Copy link
Contributor

knocte commented Dec 28, 2020

Can't use online tool in this case cause this is not reproducible there.

Using v4.4.0-alpha-007 I found a case in which fantomas was not able to format the file (will file that source-code problem separately), throwing this:

The following exception occurs while formatting stdin: Fantomas.FormatConfig+FormatException: Formatted content is not valid F# code
   at Fantomas.Extras.FakeHelpers.formatContentInternalAsync@95-5.Invoke(Boolean _arg2) in C:\Users\nojaf\Projects\fantomas\src\Fantomas.Extras\FakeHelpers.fs:line 96
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 404
   at Fantomas.CodeFormatterImpl.isValidFSharpCode@378-7.Invoke(AsyncActivation`1 ctxt) in C:\Users\nojaf\Projects\fantomas\src\Fantomas\CodeFormatterImpl.fs:line 378
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
--- End of stack trace from previous location ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 337
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInCurrentThread[a](CancellationToken cancellationToken, FSharpAsync`1 computation) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 870
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 878
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 1142
   at Program.processSourceString(Boolean isFsiFile, String s, FSharpChoice`2 tw, FormatConfig config) in C:\Users\nojaf\Projects\fantomas\src\Fantomas.CoreGlobalTool\Program.fs:line 113
   at Program.stringToFile@310(Boolean force, Boolean profile, String s, String outFile, FormatConfig config) in C:\Users\nojaf\Projects\fantomas\src\Fantomas.CoreGlobalTool\Program.fs:line 322
Processing ./NodeEffect.Server/Handlers/NodeEffectHandler.fs
./NodeEffect.Server/Handlers/NodeEffectHandler.fs has been written.
Processing ./NodeEffect.Server/Handlers/WatcherHandler.fs
The following exception occurs while formatting stdin: Fantomas.FormatConfig+FormatException: Formatted content is not valid F# code
   at Fantomas.Extras.FakeHelpers.formatContentInternalAsync@95-5.Invoke(Boolean _arg2) in C:\Users\nojaf\Projects\fantomas\src\Fantomas.Extras\FakeHelpers.fs:line 96
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 404
   at Fantomas.CodeFormatterImpl.isValidFSharpCode@378-7.Invoke(AsyncActivation`1 ctxt) in C:\Users\nojaf\Projects\fantomas\src\Fantomas\CodeFormatterImpl.fs:line 378
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
--- End of stack trace from previous location ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 337
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInCurrentThread[a](CancellationToken cancellationToken, FSharpAsync`1 computation) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 870
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 878
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 1142
   at Program.processSourceString(Boolean isFsiFile, String s, FSharpChoice`2 tw, FormatConfig config) in C:\Users\nojaf\Projects\fantomas\src\Fantomas.CoreGlobalTool\Program.fs:line 113
   at Program.stringToFile@310(Boolean force, Boolean profile, String s, String outFile, FormatConfig config) in C:\Users\nojaf\Projects\fantomas\src\Fantomas.CoreGlobalTool\Program.fs:line 322

However, the exit code was still zero, which can then not be picked up by CI pipelines, for example.

@nojaf
Copy link
Contributor

nojaf commented Jan 8, 2021

Hello @knocte, thank you for reporting this issue.
I believe a test in Fantomas.CoreGlobalTool.Tests might be able to reproduce this problem.
Would you be interested in submitting a PR for this problem?

@knocte
Copy link
Contributor Author

knocte commented Jan 13, 2021

@nojaf are you sure this can be converted into a test? I mean, I could add a new code snippet in CheckTests.fs, with the minimal testcase that I found to be reproducing this problem there. However, as I said before:

will file that source-code problem separately

As soon as I file that new bug, and it gets fixed in fantomas, then the test for this bug would begin to fail (because this time it would manage to format the file and the exit code would start to be zero).

I think this is one of this cases in which a test cannot be written, and it just needs to be fixed in the source, and tested manually.

@nojaf
Copy link
Contributor

nojaf commented Jan 20, 2021

Hey, I believe you are right. The moment the problem is resolved, the test would not work anymore.

@nojaf nojaf added the clitool Area command line tool label Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clitool Area command line tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants