Closed penelope99 closed 4 years ago
Hello @penelope99, thanks for reporting this. This is something we actually are aware of, but it never really got writing down until now 😅.
We should definitely tell the user what file caused the problem.
@lpedrosa didn't you have any strategy for this in mind?
If so could you write it down here in the issue?
That way we can label this issue as up for grabs
.
Anyone with a bit of F# knowledge should be able to pick this up.
I believe this is happening because of the way errors are reported in the CLI.
One of these functions gets called, depending on the CLIs input
@penelope99 tried to recursively format a directory while formatting the files in place, rather then storing the formatted copy somewhere else (i.e. no --out
parameter).
The bug might be in this branch of the else case, because the stringToFile
function will report errors just like in the example posted by @penelope99 i.e. "The following exception occurs while formatting stdin:"
(see here).
Some approaches to solve this problem:
check
command or;CodeFormatterImpl.format
functionRegarding the second approach, that exception is being thrown by the Fantomas.Utils.String
module. That function doesn't have any information about the file that it is processing and IMO shouldn't. Thus why you could add it in it's caller (the CodeFormatterImpl.format
).
I hope this helps.
Another instance of this same problem:
The following exception occurs while formatting stdin: System.Exception: cannot determine if synExpr DotGet
(App
(Atomic,false,Ident Baz,
Const (Unit,/tmp.fsx (262,51--262,53) IsSynthetic=false),
/tmp.fsx (262,31--262,53) IsSynthetic=false),
/tmp.fsx (262,53--262,54) IsSynthetic=false,LongIdentWithDots ([OfType],[]),
/tmp.fsx (262,31--262,60) IsSynthetic=false) is uppercase or lowercase
at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1637.Invoke(String message) in E:\A\_work\130\s\src\fsharp\FSharp.Core\printf.fs:line 1637
at Fantomas.CodePrinter.addSpaceBeforeParensInFunCall(SynExpr functionOrMethod, SynExpr arg, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 52
at Fantomas.CodePrinter.genExpr@1084-231.Invoke(Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 1086
at Fantomas.CodePrinter.genTrivia@2481-1.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 2481
at Fantomas.CodePrinter.genExpr@913-111.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 913
at Fantomas.Context.atIndentLevel@192-6.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 192
at Fantomas.Context.atIndentLevel(Boolean alsoSetIndent, Int32 level, FSharpFunc`2 f, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 188
at Fantomas.CodePrinter.genTrivia@2481-1.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 2481
at Fantomas.CodePrinter.genExpr@918-118.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 918
at Fantomas.CodePrinter.genTrivia@2481-1.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 2481
at Fantomas.Context.autoNlnCheck[a](FSharpFunc`2 f, FSharpFunc`2 sep, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 424
at Fantomas.Context.autoNlnOrAddSep(FSharpFunc`2 f, FSharpFunc`2 sep, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 456
at Fantomas.CodePrinter.genExpr@1094-242.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 1094
at Fantomas.Context.atIndentLevel@192-6.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 192
at Fantomas.Context.atIndentLevel(Boolean alsoSetIndent, Int32 level, FSharpFunc`2 f, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 188
at Fantomas.CodePrinter.genTrivia@2481-1.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 2481
at Fantomas.CodePrinter.breakNlnOrAddSpace@445-4.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 445
at Fantomas.CodePrinter.genTrivia@2481-1.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 2481
at Fantomas.CodePrinter.genExpr@1132-261.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 1132
at Fantomas.CodePrinter.genExpr@1132-262.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 1132
at Fantomas.Context.atIndentLevel@192-6.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 192
at Fantomas.Context.atIndentLevel(Boolean alsoSetIndent, Int32 level, FSharpFunc`2 f, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 188
at Fantomas.CodePrinter.genTrivia@2481-1.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 2481
at Fantomas.Context.futureNlnCheckMem(FSharpFunc`2 f, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 429
at Fantomas.Context.futureNlnCheck(FSharpFunc`2 f, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 433
at Fantomas.CodePrinter.genExprSepEqPrependType(FSharpFunc`2 genPat, ASTContext astContext, FSharpFunc`2 prefix, SynPat pat, SynExpr e, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 469
at Fantomas.CodePrinter.genTrivia@2481-1.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 2481
at Fantomas.CodePrinter.genTrivia@2481-1.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 2481
at Fantomas.Context.colEx[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 299
at Fantomas.CodePrinter.sepXs@246-2.Invoke(FSharpList`1 c, FSharpFunc`2 f, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 246
at Fantomas.CodePrinter.genModuleDeclList@252-16.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 252
at Fantomas.CodePrinter.genModuleDeclList@252-17.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 252
at Fantomas.CodePrinter.genModuleDecl@344-46.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 344
at Fantomas.CodePrinter.genTrivia@2481-1.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 2481
at Fantomas.CodePrinter.genTrivia@2481-1.Invoke(Context x) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 2481
at Fantomas.Context.col[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/Context.fs:line 289
at Fantomas.CodePrinter.genImpFile@90-6.Invoke(Context ctx) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodePrinter.fs:line 90
at Fantomas.CodeFormatterImpl.formatWith(ParsedInput ast, FSharpList`1 defines, FormatContext formatContext, FormatConfig config) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 392
at Fantomas.CodeFormatterImpl.format@408-1.Invoke(Tuple`2[] _arg1) in /home/runner/work/fantomas/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 410
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 417
at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 109
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.FSharp.Control.AsyncResult`1.Commit() in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 350
at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInCurrentThread[a](CancellationToken cancellationToken, FSharpAsync`1 computation) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 882
at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 890
at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 1154
at Program.processSourceString(Boolean isFsiFile, String s, FSharpChoice`2 tw, FormatConfig config) in /home/runner/work/fantomas/fantomas/src/Fantomas.CoreGlobalTool/Program.fs:line 96
at Program.stringToFile@303(Boolean force, Boolean profile, String s, String outFile, FormatConfig config) in /home/runner/work/fantomas/fantomas/src/Fantomas.CoreGlobalTool/Program.fs:line 311
@penelope99 , that last one might be unrelated to the CLI input.
Could you maybe try and format that file in our online tool? If it fails there, please click the create issue
link at the bottom.
"That file"? But I still don't know what files are failing.
Oh, sorry, I though I mentioned this already. I believe Fantomas will process a folder alphabetically so given the following example:
The first time my three files a,b and c were formatted correctly and the second time I added an error in b. Nevertheless you can still see that .\a.fs was written
, so it somewhat vaguely indicates that b.fs
has a problem.
Bad UX nonetheless of course.
I've tried to format a whole solution with
--recurse
, and received several errors of this type:This error message should include the file name or file path that it was trying to format, so that I can report an issue with better context, I assume.