Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
160
Issues
160
List
Board
Labels
Milestones
Merge Requests
14
Merge Requests
14
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
Commits
e45e61f2
Commit
e45e61f2
authored
Nov 16, 2023
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attach CallStack to fromDBid error
parent
1103b2c9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
1 deletion
+56
-1
gargantext.cabal
gargantext.cabal
+2
-0
Core.hs
src/Gargantext/Core.hs
+6
-1
Types.hs
src/Gargantext/Core/Errors/Types.hs
+21
-0
Errors.hs
test/Test/Offline/Errors.hs
+25
-0
Main.hs
test/drivers/tasty/Main.hs
+2
-0
No files found.
gargantext.cabal
View file @
e45e61f2
...
...
@@ -75,6 +75,7 @@ library
Gargantext.API.Prelude
Gargantext.API.Routes
Gargantext.Core
Gargantext.Core.Errors.Types
Gargantext.Core.Mail.Types
Gargantext.Core.Methods.Similarities
Gargantext.Core.NLP
...
...
@@ -948,6 +949,7 @@ test-suite garg-test-tasty
Test.Ngrams.NLP
Test.Ngrams.Query
Test.Ngrams.Query.PaginationCorpus
Test.Offline.Errors
Test.Offline.JSON
Test.Parsers.Date
Test.Parsers.Types
...
...
src/Gargantext/Core.hs
View file @
e45e61f2
...
...
@@ -25,6 +25,9 @@ import Data.Text (pack)
import
Gargantext.Prelude
hiding
(
All
)
import
Servant.API
import
Test.QuickCheck
import
Control.Exception
(
throw
)
import
Prelude
(
userError
)
import
Gargantext.Core.Errors.Types
(
WithStacktrace
(
..
))
------------------------------------------------------------------------
-- | Language of a Text
...
...
@@ -190,5 +193,7 @@ instance HasDBid PosTagAlgo where
-- with an error if the conversion cannot be performed.
fromDBid
::
forall
a
.
(
HasCallStack
,
HasDBid
a
,
Typeable
a
)
=>
Int
->
a
fromDBid
i
=
case
lookupDBid
i
of
Nothing
->
panic
$
"HasDBid "
<>
show
(
typeRep
(
Proxy
::
Proxy
a
))
<>
" not found or not implemented."
Nothing
->
let
err
=
userError
$
"HasDBid "
<>
show
(
typeRep
(
Proxy
::
Proxy
a
))
<>
" not found or not implemented."
in
throw
$
WithStacktrace
callStack
err
Just
v
->
v
src/Gargantext/Core/Errors/Types.hs
0 → 100644
View file @
e45e61f2
module
Gargantext.Core.Errors.Types
(
-- * Attaching callstacks to exceptions
WithStacktrace
(
..
)
)
where
import
Control.Exception
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
test/Test/Offline/Errors.hs
0 → 100644
View file @
e45e61f2
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
module
Test.Offline.Errors
(
tests
)
where
import
Control.Exception
import
Gargantext.Core
(
fromDBid
)
import
Gargantext.Core.Errors.Types
import
Gargantext.Database.Admin.Config
()
import
Gargantext.Database.Admin.Types.Node
import
Prelude
import
Test.Tasty
import
Test.Tasty.HUnit
tests
::
TestTree
tests
=
testGroup
"Errors"
[
testCase
"fromDBid comes with a CallStack"
fromDBid_cs
]
fromDBid_cs
::
Assertion
fromDBid_cs
=
do
res
<-
try
$
evaluate
$
fromDBid
@
NodeType
99
case
res
of
Right
r
->
fail
$
"fromDBid should have failed, but returned: "
<>
show
r
Left
(
_
::
WithStacktrace
IOError
)
->
pure
()
test/drivers/tasty/Main.hs
View file @
e45e61f2
...
...
@@ -18,6 +18,7 @@ import qualified Test.Graph.Clustering as Graph
import
qualified
Test.Ngrams.NLP
as
NLP
import
qualified
Test.Ngrams.Query
as
NgramsQuery
import
qualified
Test.Offline.JSON
as
JSON
import
qualified
Test.Offline.Errors
as
Errors
import
qualified
Test.Parsers.Date
as
PD
import
qualified
Test.Utils.Crypto
as
Crypto
import
qualified
Test.Utils.Jobs
as
Jobs
...
...
@@ -46,4 +47,5 @@ main = do
,
NgramsQuery
.
tests
,
CorpusQuery
.
tests
,
JSON
.
tests
,
Errors
.
tests
]
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