-
Notifications
You must be signed in to change notification settings - Fork 7
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
Core: ADT-ize all errors #139
Conversation
a780164
to
069021c
Compare
069021c
to
5a421fc
Compare
5a421fc
to
9f512c3
Compare
runStaticTest :: String -> Text -> (PactErrorI -> Bool) -> Assertion | ||
runStaticTest label src predicate = do | ||
isUserRecoverableError :: Prism' UserRecoverableError a -> PactErrorI -> Bool | ||
isUserRecoverableError p s = isJust $ preview (_PEUserRecoverableError . _1 . p) s |
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.
isUserRecoverableError p s = isJust $ preview (_PEUserRecoverableError . _1 . p) s | |
isUserRecoverableError p = has (_PEUserRecoverableError . _1 . p) |
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.
I'll fix it in a separate PR :D
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.
There has to be a "lens master" reaction!
pact/Pact/Core/Repl/Compile.hs
Outdated
@@ -17,6 +17,8 @@ module Pact.Core.Repl.Compile | |||
, interpretEvalBigStep | |||
, interpretEvalSmallStep | |||
, interpretEvalDirect | |||
, interpretReplProgram' |
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.
nit: Slight preference against '
names. Renaming interpretReplProgram'
to interpretReplProgramWithBuiltinEnv
, or renaming interpretReplProgram
to interpretReplProgramDefaultBuiltins
is slightly clearer.
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.
I mean the thing is that it takes an Interpreter
now, so probably should just be interpretReplProgram
. The '
version should be purely internal to the module.
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.
Fixed 👍
@@ -203,7 +205,7 @@ interpretReplProgram' interpreter (SourceCode _ source) display = do | |||
docs <- uses replUserDocs (M.lookup qn) | |||
displayValue (RUserDoc d docs) | |||
Nothing -> | |||
failInvariant varI "repl invariant violated: resolved to a top level free variable without a binder" | |||
throwExecutionError varI $ EvalError "repl invariant violated: resolved to a top level free variable without a binder" |
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.
ADT-ize this error, too? Or is that going to far?
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.
I didn't address this one, because it's a repl-only error and it's an invariant. It's not worth it.
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.
Fantastic work! I left a few very nitpicky comments, please feel free to ignore any!
@@ -254,7 +254,7 @@ sendDiagnostics nuri mv content = liftIO runPact >>= \case | |||
PEParseError{} -> "Parse" | |||
PEDesugarError{} -> "Desugar" | |||
PEExecutionError{} -> "Execution" | |||
PERecoverableError{} -> "Execution" | |||
PEUserRecoverableError{} -> "Execution" |
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.
Should it be the same as Execution
?
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.
Great question, @rsoeldner does it matter? I assumed so, it's essentially an error that happens during execution.
runStaticTest :: String -> Text -> (PactErrorI -> Bool) -> Assertion | ||
runStaticTest label src predicate = do | ||
isUserRecoverableError :: Prism' UserRecoverableError a -> PactErrorI -> Bool | ||
isUserRecoverableError p s = isJust $ preview (_PEUserRecoverableError . _1 . p) s |
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.
There has to be a "lens master" reaction!
DKDefConst -> "defconst" | ||
DKDefCap -> "defcap" | ||
DKDefPact -> "defpact" | ||
DKDefSchema _ -> "defscema" |
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.
DKDefSchema _ -> "defscema" | |
DKDefSchema _ -> "defschema" |
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.
Really good catch 👍 I've overseen it
@@ -131,7 +131,7 @@ instance J.Encode (StableEncoding KeySetName) where | |||
instance J.Encode (StableEncoding KeySet) where | |||
build (StableEncoding (KeySet keys predFun)) =J.object | |||
[ "pred" J..= StableEncoding predFun | |||
, "keys" J..= J.Array (Set.map StableEncoding keys) -- TODO: is this valid? | |||
, "keys" J..= J.Array (S.map StableEncoding keys) -- TODO: is this valid? |
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.
Since this line is touched — what kind of validity is implied here? Functoriality of this map or smth else?
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.
I Don't quite remember lol.
v' <- enforcePactValue i v | ||
maybeTCType i mty v' |
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.
Should this be moved out to a separate function to avoid having to call maybeTCType
(which can be forgotten)?
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.
I made an asana ticket for this
9f512c3
to
c44cf38
Compare
c44cf38
to
390ec3c
Compare
This PR aims to do a few things:
VError
propagating frames in the CEK machine, and theUserRecoverableError
type in the direct style)Post-this PR, the repl output becomes:
PR checklist: