-
Notifications
You must be signed in to change notification settings - Fork 44
Add context to some error messages #2017
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
rv-jenkins
merged 9 commits into
runtimeverification:master
from
ttuegel:feature--ErrorContext
Jul 31, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3f3f711
Add Pretty.prettyException
ttuegel 074b000
Add ErrorContext
ttuegel bed2b74
Kore.Internal.Condition.fromNormalizationSimplified: withErrorContext
ttuegel 500938f
Kore.Internal.Substitution.unsafeWrap: withErrorContext
ttuegel b7da340
Small cleanup
andreiburdusa dc10634
Add HasCallStack to unsafeWrapFromAssignments
ttuegel 19e09d3
Update kore/src/Kore/Internal/Substitution.hs
ttuegel 79cbc7a
Merge branch 'master' into feature--ErrorContext
ttuegel 1facd4b
Merge branch 'master' into feature--ErrorContext
rv-jenkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| {- | | ||
| Copyright : (c) Runtime Verification, 2020 | ||
| License : NCSA | ||
|
|
||
| -} | ||
|
|
||
| module ErrorContext | ||
| ( ErrorContext (..) | ||
| , withErrorContext | ||
| ) where | ||
|
|
||
| import Prelude | ||
|
|
||
| import Control.Exception | ||
| ( Exception (..) | ||
| , SomeException | ||
| , mapException | ||
| ) | ||
| import Data.String | ||
| ( fromString | ||
| ) | ||
| import Data.Typeable | ||
| ( Typeable | ||
| ) | ||
|
|
||
| import Pretty | ||
| ( Pretty | ||
| ) | ||
| import qualified Pretty | ||
|
|
||
| data ErrorContext where | ||
| ErrorContext | ||
| :: (Pretty context, Show context) | ||
| => String -- ^ A brief message (one line) introducing the context. | ||
| -> context -- ^ Some 'Pretty'-printable data for context. | ||
| -> SomeException -- ^ The error itself. | ||
| -> ErrorContext | ||
| deriving (Typeable) | ||
|
|
||
| deriving instance Show ErrorContext | ||
|
|
||
| instance Pretty ErrorContext where | ||
| pretty (ErrorContext intro context someException) = | ||
| Pretty.vsep | ||
| [ fromString intro | ||
| , Pretty.indent 4 (Pretty.pretty context) | ||
| , Pretty.prettyException someException | ||
| ] | ||
|
|
||
| instance Exception ErrorContext where | ||
| displayException = show . Pretty.pretty | ||
|
|
||
| {- | Compute a value, putting error messages in context. | ||
| -} | ||
| withErrorContext | ||
| :: (Pretty context, Show context) | ||
| => String | ||
| -> context | ||
| -> a -- ^ The value computed. | ||
| -> a | ||
| withErrorContext intro context = mapException (ErrorContext intro context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 see Ana left a "TODO" comment on line 431 about a posible refactoring. I could take care of it. What do you think @ana-pantilie @ttuegel ?
(I'm not able to comment on that line)
Uh oh!
There was an error while loading. Please reload this page.
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.
We already have
unsafeWrapFromAssignments, and it looks like the major difference between these two is thatunsafeWrapdoesn't enforce the variable renaming invariant. I believe the question here is if we want to be able to create aSubstitutionlike this, even for testing (whereunsafeWrapis most widely used). @ttuegel what do you think? Is there any reason to keepunsafeWrapthe way it is?