Skip to content

Commit 7c5632e

Browse files
committed
Print error position in errors
1 parent e0ac0a6 commit 7c5632e

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

bin/Bin/Worker.purs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import Node.Path (FilePath)
2525
import Node.WorkerBees as Worker
2626
import Partial.Unsafe (unsafeCrashWith)
2727
import PureScript.CST (RecoveredParserResult(..), parseModule)
28-
import PureScript.CST.Errors (ParseError, printParseError)
28+
import PureScript.CST.Errors (printParseError)
29+
import PureScript.CST.Parser.Monad (PositionedError)
2930
import Tidy (defaultFormatOptions, formatModule, toDoc)
3031
import Tidy.Operators (parseOperatorTable)
3132
import Tidy.Precedence (PrecedenceMap, remapOperators)
@@ -70,7 +71,7 @@ type WorkerOutput =
7071
, timing :: Number
7172
}
7273

73-
formatCommand :: FormatOptions -> PrecedenceMap -> String -> Either ParseError String
74+
formatCommand :: FormatOptions -> PrecedenceMap -> String -> Either String String
7475
formatCommand args operators contents = do
7576
let
7677
print = Dodo.print Dodo.plainText
@@ -92,9 +93,13 @@ formatCommand args operators contents = do
9293
}
9394
Right $ print $ toDoc $ formatModule opts ok
9495
ParseSucceededWithErrors _ errs -> do
95-
Left (NonEmptyArray.head errs).error
96+
Left $ printPositionedError $ NonEmptyArray.head errs
9697
ParseFailed err ->
97-
Left err.error
98+
Left $ printPositionedError err
99+
100+
printPositionedError :: PositionedError -> String
101+
printPositionedError { error, position } =
102+
"[" <> show (position.line + 1) <> ":" <> show (position.column + 1) <> "] " <> printParseError error
98103

99104
formatInPlaceCommand :: Boolean -> PrecedenceMap -> WorkerInput -> Aff WorkerOutput
100105
formatInPlaceCommand shouldCheck operators { filePath, config } = do
@@ -129,8 +134,8 @@ formatInPlaceCommand shouldCheck operators { filePath, config } = do
129134
else do
130135
FS.writeTextFile UTF8 filePath formatted
131136
pure { filePath, error: "", alreadyFormatted: false, timing }
132-
Left err ->
133-
pure { filePath, error: printParseError err, alreadyFormatted: false, timing: zero }
137+
Left error ->
138+
pure { filePath, error, alreadyFormatted: false, timing: zero }
134139

135140
main :: Effect Unit
136141
main = Worker.makeAsMain \{ receive, reply, workerData: { shouldCheck, operatorsByPath } } -> do

bin/Main.purs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import Node.Stream as Stream
5353
import Node.WorkerBees as Worker
5454
import Node.WorkerBees.Aff.Pool (poolTraverse)
5555
import PureScript.CST (RecoveredParserResult(..), parseModule, toRecovered)
56-
import PureScript.CST.Errors (printParseError)
5756
import PureScript.CST.ModuleGraph (ModuleSort(..), sortModules)
5857
import PureScript.CST.Types (Module(..), ModuleHeader(..), Name(..))
5958
import Tidy.Operators (parseOperatorTable, resolveOperatorExports)
@@ -272,7 +271,7 @@ main = launchAff_ do
272271
contents <- readStdin
273272
case formatCommand options operators contents of
274273
Left err -> do
275-
Console.error $ printParseError err
274+
Console.error err
276275
liftEffect $ Process.exit 1
277276
Right str ->
278277
makeAff \k -> do

0 commit comments

Comments
 (0)