1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 01:42:43 +03:00

Wrap LoadError in BaseError

This commit is contained in:
Rick Winfrey 2018-08-06 15:05:58 -07:00
parent 1b914f8ba6
commit 5ecb611d48
3 changed files with 11 additions and 13 deletions

View File

@ -76,14 +76,14 @@ sendModules :: Member (Modules address) effects => Modules address (Eff effects)
sendModules = send
runModules :: ( Member (Reader (ModuleTable (NonEmpty (Module (ModuleResult address))))) effects
, Member (Resumable (LoadError address)) effects
, Member (Resumable (BaseError (LoadError address))) effects
, PureEffects effects
)
=> Set ModulePath
-> Evaluator address value (Modules address ': effects) a
-> Evaluator address value effects a
runModules paths = interpret $ \case
Load name -> fmap (runMerging . foldMap1 (Merging . moduleBody)) . ModuleTable.lookup name <$> askModuleTable >>= maybeM (throwResumable $ ModuleNotFoundError name)
Load name -> fmap (runMerging . foldMap1 (Merging . moduleBody)) . ModuleTable.lookup name <$> askModuleTable >>= maybeM (throwLoadError (ModuleNotFoundError name))
Lookup path -> fmap (runMerging . foldMap1 (Merging . moduleBody)) . ModuleTable.lookup path <$> askModuleTable
Resolve names -> pure (find (`Set.member` paths) names)
List dir -> pure (filter ((dir ==) . takeDirectory) (toList paths))
@ -109,19 +109,16 @@ instance Show1 (LoadError address) where
instance Eq1 (LoadError address) where
liftEq _ (ModuleNotFoundError a) (ModuleNotFoundError b) = a == b
runLoadError :: (Effectful (m address value), Effects effects) => m address value (Resumable (LoadError address) ': effects) a -> m address value effects (Either (SomeExc (LoadError address)) a)
runLoadError :: (Effectful (m address value), Effects effects) => m address value (Resumable (BaseError (LoadError address)) ': effects) a -> m address value effects (Either (SomeExc (BaseError (LoadError address))) a)
runLoadError = runResumable
runLoadErrorWith :: (Effectful (m address value), Effects effects) => (forall resume . (LoadError address) resume -> m address value effects resume) -> m address value (Resumable (LoadError address) ': effects) a -> m address value effects a
runLoadErrorWith :: (Effectful (m address value), Effects effects) => (forall resume . (BaseError (LoadError address)) resume -> m address value effects resume) -> m address value (Resumable (BaseError (LoadError address)) ': effects) a -> m address value effects a
runLoadErrorWith = runResumableWith
throwLoadError :: ( Member (Reader ModuleInfo) effects
, Member (Reader Span) effects
, Member (Resumable (BaseError (LoadError address))) effects
)
throwLoadError :: Member (Resumable (BaseError (LoadError address))) effects
=> LoadError address resume
-> Evaluator address value effects resume
throwLoadError err = currentErrorContext >>= \ errorContext -> throwResumable $ BaseError errorContext err
throwLoadError err = throwResumable $ BaseError (ErrorContext lowerBound lowerBound) err
-- | An error thrown when we can't resolve a module from a qualified name.

View File

@ -202,7 +202,7 @@ newtype ImportGraphEff address outerEffects a = ImportGraphEff
': Resumable (BaseError EvalError)
': Resumable (BaseError (EnvironmentError address))
': Resumable (BaseError (UnspecializedError (Value address (ImportGraphEff address outerEffects))))
': Resumable (LoadError address)
': Resumable (BaseError (LoadError address))
': Fresh
': State (Heap address Latest (Value address (ImportGraphEff address outerEffects)))
': outerEffects
@ -248,8 +248,9 @@ resumingResolutionError = runResolutionErrorWith (\ (BaseError context err) -> t
NotFoundError nameToResolve _ _ -> pure nameToResolve
GoImportError pathToResolve -> pure [pathToResolve])
resumingLoadError :: (AbstractHole address, Effectful (m address value), Effects effects, Functor (m address value effects), Member Trace effects) => m address value (Resumable (LoadError address) ': effects) a -> m address value effects a
resumingLoadError = runLoadErrorWith (\ (ModuleNotFoundError path) -> trace ("LoadError: " <> prettyShow path) $> (lowerBound, hole))
resumingLoadError :: (Applicative (m address value effects), AbstractHole address, Effectful (m address value), Effects effects, Member Trace effects) => m address value (Resumable (BaseError (LoadError address)) ': effects) a -> m address value effects a
resumingLoadError = runLoadErrorWith (\ (BaseError context err) -> traceError "LoadError" err context *> case err of
ModuleNotFoundError _ -> pure (lowerBound, hole))
resumingEvalError :: (Applicative (m effects), Effectful m, Effects effects, Member Fresh effects, Member Trace effects) => m (Resumable (BaseError EvalError) ': effects) a -> m effects a
resumingEvalError = runEvalErrorWith (\ (BaseError context err) -> traceError "EvalError" err context *> case err of

View File

@ -70,7 +70,7 @@ newtype UtilEff a = UtilEff
, Resumable (BaseError EvalError)
, Resumable (BaseError (EnvironmentError Precise))
, Resumable (BaseError (UnspecializedError (Value Precise UtilEff)))
, Resumable (LoadError Precise)
, Resumable (BaseError (LoadError Precise))
, Trace
, Fresh
, State (Heap Precise Latest (Value Precise UtilEff))