Skip to content

Commit 29cbb55

Browse files
authored
Fix a parser error when an error position is missing (#93)
* Fix a parser error when an error position is missing * Fix warning
1 parent 88903cf commit 29cbb55

File tree

3 files changed

+81
-32
lines changed

3 files changed

+81
-32
lines changed

js/index.js

Lines changed: 69 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Main.purs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import Data.FoldableWithIndex (forWithIndex_)
2323
import Data.Foreign (renderForeignError)
2424
import Data.Maybe (Maybe(..), fromMaybe)
2525
import Data.Newtype (unwrap)
26+
import Data.StrMap as StrMap
2627
import Data.String (joinWith)
2728
import Data.String as String
2829
import Data.String.Regex (replace')
2930
import Data.String.Regex.Flags (global)
3031
import Data.String.Regex.Unsafe (unsafeRegex)
31-
import Data.StrMap as StrMap
3232
import Try.API (BackendConfig(..), CompileError(..), CompileResult(..), CompilerError(..), ErrorPosition(..), FailedResult(..), SuccessResult(..), getBackendConfigFromString)
3333
import Try.API as API
3434
import Try.Gist (getGistById, tryLoadFileFromGist, uploadGist)
@@ -51,7 +51,7 @@ displayErrors :: forall eff. Array CompilerError -> Eff (dom :: DOM | eff) Unit
5151
displayErrors errs = do
5252
column2 <- JQuery.select "#column2"
5353
JQuery.empty column2
54-
forWithIndex_ errs \i (CompilerError{ message, position: ErrorPosition pos }) -> do
54+
forWithIndex_ errs \i (CompilerError{ message }) -> do
5555
h1 <- JQuery.create "<h1>"
5656
JQuery.addClass "error-banner" h1
5757
JQuery.appendText ("Error " <> show (i + 1) <> " of " <> show (Array.length errs)) h1
@@ -174,12 +174,13 @@ compile bc@(BackendConfig backend) = do
174174
CompilerErrors errs -> do
175175
displayErrors errs
176176

177-
for_ errs \(CompilerError{ position: ErrorPosition pos }) -> do
178-
runEffFn4 addErrorMarker
179-
pos.startLine
180-
pos.startColumn
181-
pos.endLine
182-
pos.endColumn
177+
for_ errs \(CompilerError{ position }) ->
178+
for_ (unwrap position) \(ErrorPosition pos) ->
179+
runEffFn4 addErrorMarker
180+
pos.startLine
181+
pos.startColumn
182+
pos.endLine
183+
pos.endColumn
183184
OtherError err -> displayPlainText err
184185
Left errs -> do
185186
displayPlainText "Unable to parse the response from the server"

src/Try/API.purs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Data.Foreign (Foreign, ForeignError)
2727
import Data.Foreign.Class (class Decode, decode)
2828
import Data.Foreign.Generic (defaultOptions, genericDecode)
2929
import Data.Foreign.Generic.Types (Options, SumEncoding(..))
30+
import Data.Foreign.NullOrUndefined (NullOrUndefined)
3031
import Data.Generic.Rep (class Generic)
3132
import Data.List.NonEmpty (NonEmptyList)
3233
import Data.String.Regex (replace)
@@ -53,7 +54,7 @@ instance decodeErrorPosition :: Decode ErrorPosition where
5354

5455
newtype CompilerError = CompilerError
5556
{ message :: String
56-
, position :: ErrorPosition
57+
, position :: NullOrUndefined ErrorPosition
5758
}
5859

5960
derive instance genericCompilerError :: Generic CompilerError _
@@ -233,7 +234,7 @@ getBackendConfig Slides = BackendConfig
233234
, compile: compile "https://compile.purescript.org/slides"
234235
, getBundle: getDefaultBundle "https://compile.purescript.org/slides"
235236
}
236-
getBackendConfig Mathbox = BackendConfig
237+
getBackendConfig Mathbox = BackendConfig
237238
{ backend: "mathbox"
238239
, mainGist: "aeecffd458fa8a365b4af3b3cd9d7759"
239240
, extra_styling: fold

0 commit comments

Comments
 (0)