Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext-prelude
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext-prelude
Commits
e7b5aff0
Commit
e7b5aff0
authored
Dec 04, 2023
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce panicTrace and errorTrace
parent
fec7427b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
1 deletion
+59
-1
gargantext-prelude.cabal
gargantext-prelude.cabal
+1
-0
Prelude.hs
src/Gargantext/Prelude.hs
+15
-1
Error.hs
src/Gargantext/Prelude/Error.hs
+43
-0
No files found.
gargantext-prelude.cabal
View file @
e7b5aff0
...
@@ -36,6 +36,7 @@ library
...
@@ -36,6 +36,7 @@ library
Gargantext.Prelude.Crypto.Share
Gargantext.Prelude.Crypto.Share
Gargantext.Prelude.Crypto.Symmetric
Gargantext.Prelude.Crypto.Symmetric
Gargantext.Prelude.Database
Gargantext.Prelude.Database
Gargantext.Prelude.Error
Gargantext.Prelude.Fibonacci
Gargantext.Prelude.Fibonacci
Gargantext.Prelude.Mail
Gargantext.Prelude.Mail
Gargantext.Prelude.Mail.Types
Gargantext.Prelude.Mail.Types
...
...
src/Gargantext/Prelude.hs
View file @
e7b5aff0
...
@@ -18,6 +18,7 @@ module Gargantext.Prelude
...
@@ -18,6 +18,7 @@ module Gargantext.Prelude
,
module
Protolude
,
module
Protolude
,
module
Data
.
String
.
Conversions
,
module
Data
.
String
.
Conversions
,
MonadBase
(
..
)
,
MonadBase
(
..
)
,
module
Gargantext
.
Prelude
.
Error
)
)
where
where
...
@@ -34,14 +35,27 @@ import Data.Semigroup (Semigroup, (<>))
...
@@ -34,14 +35,27 @@ import Data.Semigroup (Semigroup, (<>))
import
Data.Set
(
Set
)
import
Data.Set
(
Set
)
import
Data.Set
qualified
as
Set
import
Data.Set
qualified
as
Set
import
Data.String.Conversions
(
ConvertibleStrings
,
cs
)
import
Data.String.Conversions
(
ConvertibleStrings
,
cs
)
import
Data.Text
(
Text
)
import
Data.Typeable
(
Typeable
)
import
Data.Typeable
(
Typeable
)
import
Data.Vector
qualified
as
V
import
Data.Vector
qualified
as
V
import
GHC.Exts
(
sortWith
)
import
GHC.Exts
(
sortWith
)
import
GHC.Real
(
round
)
import
GHC.Real
(
round
)
import
Protolude
import
Protolude
hiding
(
panic
)
import
Protolude
qualified
as
Proto
import
Prelude
qualified
as
GHCPrelude
import
Gargantext.Prelude.Error
import
System.Directory
(
createDirectoryIfMissing
)
import
System.Directory
(
createDirectoryIfMissing
)
import
System.FilePath.Posix
(
takeDirectory
)
import
System.FilePath.Posix
(
takeDirectory
)
-- Version of panic and error with an explicit warning.
panic
::
Text
->
a
panic
=
Proto
.
panic
{-# DEPRECATED panic "'panic' doesn't attach a stacktrace to the error. Please use 'panicTrace'" #-}
error
::
GHCPrelude
.
String
->
a
error
=
GHCPrelude
.
error
{-# DEPRECATED error "'error' doesn't attach a stacktrace to the error. Please use 'errorTrace'" #-}
printDebug
::
(
Show
a
,
MonadBase
IO
m
)
=>
Text
->
a
->
m
()
printDebug
::
(
Show
a
,
MonadBase
IO
m
)
=>
Text
->
a
->
m
()
printDebug
msg
x
=
liftBase
.
putStrLn
$
msg
<>
" "
<>
show
x
printDebug
msg
x
=
liftBase
.
putStrLn
$
msg
<>
" "
<>
show
x
...
...
src/Gargantext/Prelude/Error.hs
0 → 100644
View file @
e7b5aff0
module
Gargantext.Prelude.Error
(
-- * Attaching callstacks to exceptions
WithStacktrace
(
..
)
,
UnexpectedPanic
(
..
)
,
withStacktrace
-- * Drop-in replacement for panic/error
,
panicTrace
,
errorTrace
)
where
import
Control.Exception
import
Data.Text
qualified
as
T
import
GHC.Stack
import
Prelude
-- | A 'WithStacktrace' carries an error alongside its
-- 'CallStack', to be able to print the correct source location
-- of where the error originated.
data
WithStacktrace
e
=
WithStacktrace
{
ct_callStack
::
!
CallStack
,
ct_error
::
!
e
}
deriving
Show
instance
Exception
e
=>
Exception
(
WithStacktrace
e
)
where
displayException
WithStacktrace
{
..
}
=
displayException
ct_error
<>
"
\n
"
<>
prettyCallStack
ct_callStack
withStacktrace
::
HasCallStack
=>
e
->
WithStacktrace
e
withStacktrace
=
withFrozenCallStack
.
WithStacktrace
callStack
newtype
UnexpectedPanic
=
UnexpectedPanic
T
.
Text
deriving
Show
instance
Exception
UnexpectedPanic
panicTrace
::
HasCallStack
=>
T
.
Text
->
x
panicTrace
=
throw
.
withFrozenCallStack
.
WithStacktrace
callStack
.
UnexpectedPanic
-- | Drop-in replacement for Prelude's 'error'.
errorTrace
::
HasCallStack
=>
String
->
x
errorTrace
=
panicTrace
.
T
.
pack
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment