Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar
Commits
19653c9f
Commit
19653c9f
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add ExceptionChannel helper implementations
parent
9413c427
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Quasar/Exceptions/ExceptionChannel.hs
+41
-0
41 additions, 0 deletions
src/Quasar/Exceptions/ExceptionChannel.hs
with
41 additions
and
0 deletions
src/Quasar/Exceptions/ExceptionChannel.hs
+
41
−
0
View file @
19653c9f
module
Quasar.Exceptions.ExceptionChannel
(
module
Quasar.Exceptions.ExceptionChannel
(
panicChannel
,
panicChannel
,
loggingExceptionChannel
,
loggingExceptionChannel
,
newExceptionChannelWitness
,
newExceptionRedirector
,
newExceptionCollector
)
where
)
where
import
Control.Concurrent
(
forkIO
)
import
Control.Concurrent
(
forkIO
)
...
@@ -36,3 +39,41 @@ loggingExceptionChannel worker =
...
@@ -36,3 +39,41 @@ loggingExceptionChannel worker =
where
where
logFn
::
SomeException
->
ShortIO
()
logFn
::
SomeException
->
ShortIO
()
logFn
ex
=
unsafeShortIO
$
Trace
.
traceIO
$
displayException
ex
logFn
ex
=
unsafeShortIO
$
Trace
.
traceIO
$
displayException
ex
newExceptionChannelWitness
::
ExceptionChannel
->
STM
(
ExceptionChannel
,
STM
Bool
)
newExceptionChannelWitness
exChan
=
do
var
<-
newTVar
False
let
chan
=
ExceptionChannel
\
ex
->
lock
var
>>
throwToExceptionChannel
exChan
ex
pure
(
chan
,
readTVar
var
)
where
lock
::
TVar
Bool
->
STM
()
lock
var
=
unlessM
(
readTVar
var
)
(
writeTVar
var
True
)
newExceptionRedirector
::
ExceptionChannel
->
STM
(
ExceptionChannel
,
ExceptionChannel
->
STM
()
)
newExceptionRedirector
initialExceptionChannel
=
do
channelVar
<-
newTVar
initialExceptionChannel
pure
(
ExceptionChannel
(
channelFn
channelVar
),
writeTVar
channelVar
)
where
channelFn
::
TVar
ExceptionChannel
->
SomeException
->
STM
()
channelFn
channelVar
ex
=
do
channel
<-
readTVar
channelVar
throwToExceptionChannel
channel
ex
-- | Collects exceptions. After they have been collected (by using the resulting
-- transaction), further exceptions are forwarded to the backup exception sink.
-- The collection transaction may only be used once.
newExceptionCollector
::
ExceptionChannel
->
STM
(
ExceptionChannel
,
STM
[
SomeException
])
newExceptionCollector
backupExceptionChannel
=
do
exceptionsVar
<-
newTVar
(
Just
[]
)
pure
(
ExceptionChannel
(
channelFn
exceptionsVar
),
gatherResult
exceptionsVar
)
where
channelFn
::
TVar
(
Maybe
[
SomeException
])
->
SomeException
->
STM
()
channelFn
exceptionsVar
ex
=
do
readTVar
exceptionsVar
>>=
\
case
Just
exceptions
->
writeTVar
exceptionsVar
(
Just
(
ex
:
exceptions
))
Nothing
->
throwToExceptionChannel
backupExceptionChannel
ex
gatherResult
::
TVar
(
Maybe
[
SomeException
])
->
STM
[
SomeException
]
gatherResult
exceptionsVar
=
swapTVar
exceptionsVar
Nothing
>>=
\
case
Just
exceptions
->
pure
exceptions
Nothing
->
throwSTM
$
userError
"Exception collector result can only be generated once."
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment