Skip to content

Display FFI errors to user #268

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

Merged

Conversation

pete-murphy
Copy link
Contributor

@pete-murphy pete-murphy commented Feb 5, 2022

Description of the change

Fixes #265

These are minimal changes to render an error message in the case of a missing FFI dependency. We are displaying the message in the right pane (using the same renderPlainText function that's used for displaying the JS output for example) as well as throwing an error so that it's visible in the browser console. If there are multiple missing dependencies, only the first will be rendered to the user.

I looked into accumulating an array of misses using Data.Validation.Semigroup in #267, but I don't know that the added complexity was justified, since it seems like there would rarely be more than a single missing FFI dep.

Screenshots

Single missing FFI dependency

Before
image

After
Screen Shot 2022-02-05 at 4 24 15 PM

Multiple missing FFI dependencies Same error messages as single-missing, even though puppeteer is another missing dependency here.

Before
image

After
image

Server error Simulated by setting Try.Config.loaderUrl to a non-existent URL

Before (not sure why this isn't showing "Unable to parse the response from the server.")
image

After
Screen Shot 2022-02-05 at 4 31 33 PM

Successfully compiled code I added word-wrap to the code tag rendered by renderPlainText to avoid horizontal scrolling for error messages, which also affects how the compiled JS looks (maybe not for the better 🤷 )

Before
image

After
image


Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0 by @)")
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@pete-murphy pete-murphy mentioned this pull request Feb 5, 2022
4 tasks
@pete-murphy pete-murphy marked this pull request as ready for review February 5, 2022 22:25
@pete-murphy
Copy link
Contributor Author

Not sure why pete-murphy@50a500a isn't showing up here 🤔 maybe GH is just slow to sync

@@ -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!

@@ -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.

@pete-murphy pete-murphy force-pushed the pm/265/show-ffi-errors branch 2 times, most recently from c72418a to c0d4669 Compare February 5, 2022 23:31
@thomashoneyman thomashoneyman merged commit be1580f into purescript:master Feb 5, 2022
@thomashoneyman
Copy link
Member

Thanks!

@pete-murphy pete-murphy deleted the pm/265/show-ffi-errors branch February 5, 2022 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uncaught Error: FFI dependency not provided: url
2 participants