1
- {-# LANGUAGE ExistentialQuantification, DuplicateRecordFields, GeneralizedNewtypeDeriving, DerivingStrategies, DeriveGeneric, DerivingVia, RecordWildCards #-}
1
+ {-# LANGUAGE ExistentialQuantification, DuplicateRecordFields, GeneralizedNewtypeDeriving, DerivingStrategies, DeriveGeneric, RecordWildCards #-}
2
2
3
3
module Quickjs.Error where
4
4
import Control.Exception (Exception (.. ), SomeException )
@@ -32,40 +32,40 @@ jsRuntimeExceptionFromException x = do
32
32
cast a
33
33
34
34
35
- newtype JSRuntimeException e = JSRuntimeException e
36
- deriving Generic
37
- deriving newtype Show
38
-
39
- instance (Show e , Typeable e ) => Exception (JSRuntimeException e )
40
- where
41
- toException = jsRuntimeExceptionToException
42
- fromException = jsRuntimeExceptionFromException
43
-
44
-
45
35
46
36
instance ToJSON CLong where
47
37
toJSON cl = toJSON (fromIntegral cl :: Integer )
48
38
49
39
data UnknownJSTag = UnknownJSTag { raw_tag :: ! CLong }
50
40
deriving (Generic , Typeable )
51
- deriving Exception via (JSRuntimeException UnknownJSTag )
41
+
42
+ instance Exception UnknownJSTag where
43
+ toException = jsRuntimeExceptionToException
44
+ fromException = jsRuntimeExceptionFromException
45
+
52
46
53
47
instance Show UnknownJSTag where
54
48
show UnknownJSTag {.. } = " Uknown JS tag: " ++ show raw_tag
55
49
56
50
57
51
data UnsupportedTypeTag = UnsupportedTypeTag { _tag :: JSTagEnum }
58
52
deriving (Generic , Typeable )
59
- deriving Exception via (JSRuntimeException UnsupportedTypeTag )
60
53
54
+ instance Exception UnsupportedTypeTag where
55
+ toException = jsRuntimeExceptionToException
56
+ fromException = jsRuntimeExceptionFromException
61
57
62
58
instance Show UnsupportedTypeTag where
63
59
show UnsupportedTypeTag {.. } = " Unsupported type tag: " ++ show _tag
64
60
65
61
66
62
data JSException = JSException { location :: Text , message :: Text }
67
63
deriving (Generic , Typeable )
68
- deriving Exception via (JSRuntimeException JSException )
64
+
65
+ instance Exception JSException where
66
+ toException = jsRuntimeExceptionToException
67
+ fromException = jsRuntimeExceptionFromException
68
+
69
69
70
70
instance Show JSException where
71
71
show JSException {.. } = " JS runtime threw an exception in " ++ toS location ++ " :\n =================\n " ++ toS message ++ " \n =================\n "
@@ -74,7 +74,11 @@ instance Show JSException where
74
74
75
75
data JSValueUndefined = JSValueUndefined { value :: Text }
76
76
deriving (Generic , Typeable )
77
- deriving Exception via (JSRuntimeException JSValueUndefined )
77
+
78
+ instance Exception JSValueUndefined where
79
+ toException = jsRuntimeExceptionToException
80
+ fromException = jsRuntimeExceptionFromException
81
+
78
82
79
83
instance Show JSValueUndefined where
80
84
show JSValueUndefined {.. } = " The JS value '" ++ toS value ++ " ' is undefined."
@@ -87,15 +91,22 @@ data JSValueIncorrectType =
87
91
, found :: JSTypeEnum
88
92
}
89
93
deriving (Generic , Typeable )
90
- deriving Exception via (JSRuntimeException JSValueIncorrectType )
94
+
95
+ instance Exception JSValueIncorrectType where
96
+ toException = jsRuntimeExceptionToException
97
+ fromException = jsRuntimeExceptionFromException
98
+
91
99
92
100
instance Show JSValueIncorrectType where
93
101
show JSValueIncorrectType {.. } = " Type mismatch of the JS value '" ++ toS name ++ " '. Expected: " ++ show expected ++ " , found: " ++ show found
94
102
95
103
96
104
data InternalError = InternalError { message :: Text }
97
105
deriving (Generic , Typeable )
98
- deriving Exception via (JSRuntimeException InternalError )
106
+
107
+ instance Exception InternalError where
108
+ toException = jsRuntimeExceptionToException
109
+ fromException = jsRuntimeExceptionFromException
99
110
100
111
instance Show InternalError where
101
112
show InternalError {.. } = " Internal error occured:\n " ++ toS message
0 commit comments