-
Notifications
You must be signed in to change notification settings - Fork 50
265/show ffi errors to user #267
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module Try.App | ||
( AppT(..) | ||
, Error(..) | ||
, ParAppT | ||
, displayError | ||
, runAppT | ||
) where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Error.Class (class MonadThrow) | ||
import Control.Monad.Except (ExceptT(..)) | ||
import Control.Monad.Except as ExceptT | ||
import Control.Parallel as Parallel | ||
import Control.Parallel.Class (class Parallel) | ||
import Data.Array.NonEmpty (NonEmptyArray) | ||
import Data.Array.NonEmpty as NonEmpty | ||
import Data.Either as Either | ||
import Data.Foldable (length) | ||
import Data.Functor.Compose (Compose(..)) | ||
import Data.Newtype as Newtype | ||
import Data.String (joinWith) | ||
import Data.Validation.Semigroup (V) | ||
import Data.Validation.Semigroup as V | ||
import Effect.Aff.Class (class MonadAff) | ||
import Effect.Class (class MonadEffect) | ||
|
||
data Error | ||
= FetchError String | ||
| FFIErrors (NonEmptyArray String) | ||
|
||
instance semigroupError :: Semigroup Error where | ||
append (FFIErrors errs) (FFIErrors errs') = FFIErrors (errs <> errs') | ||
append err _ = err | ||
|
||
displayError :: Error -> String | ||
displayError = case _ of | ||
FetchError err -> err | ||
FFIErrors errs -> do | ||
let dependencies | ||
| length errs == 1 = "dependency" | ||
| otherwise = "dependencies" | ||
"FFI " <> dependencies <> " not provided: " <> joinWith ", " (NonEmpty.toArray errs) | ||
|
||
newtype AppT (m :: Type -> Type) a = AppT (ExceptT Error m a) | ||
|
||
derive newtype instance functorApp :: Functor m => Functor (AppT m) | ||
derive newtype instance applyApp :: Monad m => Apply (AppT m) | ||
derive newtype instance applicativeApp :: Monad m => Applicative (AppT m) | ||
derive newtype instance bindApp :: Monad m => Bind (AppT m) | ||
derive newtype instance monadApp :: Monad m => Monad (AppT m) | ||
derive newtype instance monadEffectApp :: MonadEffect m => MonadEffect (AppT m) | ||
derive newtype instance monadAffApp :: MonadAff m => MonadAff (AppT m) | ||
derive newtype instance monadThrowApp :: Monad m => MonadThrow Error (AppT m) | ||
|
||
runAppT :: forall m. AppT m ~> ExceptT Error m | ||
runAppT (AppT x) = x | ||
|
||
newtype ParAppT m a = ParAppT (Compose m (V Error) a) | ||
|
||
derive newtype instance functorParApp :: Functor m => Functor (ParAppT m) | ||
derive newtype instance applyParApp :: Apply m => Apply (ParAppT m) | ||
derive newtype instance applicativeParApp :: Applicative m => Applicative (ParAppT m) | ||
|
||
runParAppT :: forall f. ParAppT f ~> Compose f (V Error) | ||
runParAppT (ParAppT x) = x | ||
|
||
instance parallelParAppApp :: Parallel f m => Parallel (ParAppT f) (AppT m) where | ||
parallel = | ||
ParAppT | ||
<<< Compose | ||
<<< map (Either.either V.invalid pure) | ||
<<< Parallel.parallel | ||
<<< ExceptT.runExceptT | ||
<<< runAppT | ||
sequential = | ||
AppT | ||
<<< ExceptT | ||
<<< map (V.toEither) | ||
<<< Parallel.sequential | ||
<<< Newtype.unwrap | ||
<<< runParAppT | ||
Comment on lines
+47
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of this just so I can call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think I'll remove this. It was an interesting experiment to enable showing warnings for all missing FFI dependencies while loading in parallel, but it seems like in practice there's rarely a situation where there'd be more than one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Realizing that I probably want to capture all the errors here, so
CompilerErrors
as well, though I'm not sure why those are currently tracked separately from the error type ofExceptT
. For exampletrypurescript/client/src/Try/API.purs
Line 101 in 0bd14e2
String
s (inExceptT String
andEither String
) and the possibility ofCompileResult
to beCompileFailed
.