Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/public/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ pre code {
background: none;
border: 0;
margin: 0;
overflow-x: auto;
white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;
}

iframe {
Expand Down
23 changes: 14 additions & 9 deletions client/src/Try/Container.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Ace (Annotation)
import Control.Monad.Except (runExceptT)
import Data.Array (fold)
import Data.Array as Array
import Data.Either (Either(..), hush)
import Data.Either (Either(..))
import Data.Foldable (for_, oneOf)
import Data.FoldableWithIndex (foldMapWithIndex)
import Data.Maybe (Maybe(..), fromMaybe, isNothing)
Expand Down Expand Up @@ -189,17 +189,22 @@ component = H.mkComponent
if settings.showJs then
H.liftEffect teardownIFrame
else do
mbSources <- H.liftAff $ map hush $ runExceptT $ runLoader loader (JS js)
eitherSources <- H.liftAff $ runExceptT $ runLoader loader (JS js)
for_ warnings \warnings_ -> do
let anns = Array.mapMaybe (toAnnotation MarkerWarning) warnings_
_ <- H.query _editor unit $ H.tell $ Editor.SetAnnotations anns
pure unit
for_ mbSources \sources -> do
let eventData = Object.insert "<file>" (JS js) sources
H.liftAff $ makeAff \f -> do
runEffectFn3 setupIFrame eventData (f (Right unit)) (f (Left $ Aff.error "Could not load iframe"))
mempty
H.modify_ _ { compiled = Just (Right res) }
case eitherSources of
Right sources -> do
let eventData = Object.insert "<file>" (JS js) sources
H.liftAff $ makeAff \f -> do
runEffectFn3 setupIFrame eventData (f (Right unit)) (f (Left $ Aff.error "Could not load iframe"))
mempty
H.modify_ _ { compiled = Just (Right res) }
Left err -> do
H.liftEffect teardownIFrame
H.liftEffect $ error err
H.modify_ _ { compiled = Just (Left err) }

HandleEditor (Editor.TextChanged text) -> do
_ <- H.fork $ handleAction $ Cache text
Expand Down Expand Up @@ -383,7 +388,7 @@ component = H.mkComponent

renderCompiled = case _ of
Left err ->
renderPlaintext "Unable to parse the response from the server."
Copy link
Contributor Author

@pete-murphy pete-murphy Feb 5, 2022

Choose a reason for hiding this comment

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

Ah, just realized why we weren't hitting this case even if we pass a bad loaderUrl. This line

H.modify_ _ { compiled = Just (Right res) }
was always running regardless of whatever errors happened when running the loader.

renderPlaintext err
Right res -> case res of
CompileFailed { error } -> case error of
OtherError err ->
Expand Down
7 changes: 2 additions & 5 deletions client/src/Try/Loader.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Try.Loader
import Prelude

import Control.Bind (bindFlipped)
import Control.Monad.Except (ExceptT)
import Control.Monad.Except (ExceptT, throwError)
import Control.Parallel (parTraverse)
import Data.Array as Array
import Data.Array.NonEmpty as NonEmpty
Expand Down Expand Up @@ -112,7 +112,7 @@ makeLoader rootPath = Loader (go Object.empty <<< parseDeps "<file>")
deps = { name: _, path: Nothing } <$> shim.deps
pure { name, path, deps, src }
Nothing ->
pure { name, path, deps: [], src: ffiDep name }
throwError ("FFI dependency not provided: " <> name)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just copied the error message from the ffiDep that this replaces, but maybe there could be more info here about why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe:

Compilation succeeded, but the following FFI dependency is missing:
- url

We don't provide FFI shims for all libraries in the PureScript package sets; you can't execute Node libraries on Try PureScript.

(Adapted from #265 (comment) 🙂 )

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps: "We don't provide FFI shims for all libraries; for example, Node libraries are not supported on Try PureScript. If you would like to suggest a new FFI shim be supported, please open an issue."

Copy link
Contributor Author

@pete-murphy pete-murphy Feb 5, 2022

Choose a reason for hiding this comment

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

Updated the copy here:
image

However I also realized that rendering this error message prevents the compiled JS code from displaying, since both want to set to the compiled state ... 😬

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine to surface this error in the iframe instead of only in the console. However, if we find a better place to put it in the future, then I'm happy to move it around!

liftEffect $ putModule name mod
pure mod

Expand All @@ -130,6 +130,3 @@ makeLoader rootPath = Loader (go Object.empty <<< parseDeps "<file>")
# bindFlipped _.deps
# Array.nubBy (comparing _.name)
# go ms'

ffiDep :: String -> JS
ffiDep name = JS $ "throw new Error('FFI dependency not provided: " <> name <> "');"