Skip to content

Commit bf46294

Browse files
committed
Use Error rather than String type errors
1 parent aadd264 commit bf46294

File tree

5 files changed

+58
-58
lines changed

5 files changed

+58
-58
lines changed

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
### Types
2525

26-
type Callback eff a = Either String a -> Eff eff Unit
26+
type Callback eff a = Either Error a -> Eff eff Unit
2727

2828

2929
### Values
@@ -115,46 +115,46 @@
115115

116116
### Values
117117

118-
appendFile :: forall eff. FilePath -> Buffer -> Eff (fs :: FS | eff) (Either String Unit)
118+
appendFile :: forall eff. FilePath -> Buffer -> Eff (fs :: FS | eff) (Either Error Unit)
119119

120-
appendTextFile :: forall eff. Encoding -> FilePath -> String -> Eff (fs :: FS | eff) (Either String Unit)
120+
appendTextFile :: forall eff. Encoding -> FilePath -> String -> Eff (fs :: FS | eff) (Either Error Unit)
121121

122-
chmod :: forall eff. FilePath -> Number -> Eff (fs :: FS | eff) (Either String Unit)
122+
chmod :: forall eff. FilePath -> Number -> Eff (fs :: FS | eff) (Either Error Unit)
123123

124-
chown :: forall eff. FilePath -> Number -> Number -> Eff (fs :: FS | eff) (Either String Unit)
124+
chown :: forall eff. FilePath -> Number -> Number -> Eff (fs :: FS | eff) (Either Error Unit)
125125

126-
link :: forall eff. FilePath -> FilePath -> Eff (fs :: FS | eff) (Either String Unit)
126+
link :: forall eff. FilePath -> FilePath -> Eff (fs :: FS | eff) (Either Error Unit)
127127

128-
mkdir :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either String Unit)
128+
mkdir :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either Error Unit)
129129

130-
mkdir' :: forall eff. FilePath -> Number -> Eff (fs :: FS | eff) (Either String Unit)
130+
mkdir' :: forall eff. FilePath -> Number -> Eff (fs :: FS | eff) (Either Error Unit)
131131

132-
readFile :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either String Buffer)
132+
readFile :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either Error Buffer)
133133

134-
readTextFile :: forall eff. Encoding -> FilePath -> Eff (fs :: FS | eff) (Either String String)
134+
readTextFile :: forall eff. Encoding -> FilePath -> Eff (fs :: FS | eff) (Either Error String)
135135

136-
readdir :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either String [FilePath])
136+
readdir :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either Error [FilePath])
137137

138-
readlink :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either String FilePath)
138+
readlink :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either Error FilePath)
139139

140-
realpath :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either String FilePath)
140+
realpath :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either Error FilePath)
141141

142-
realpath' :: forall eff cache. FilePath -> { | cache } -> Eff (fs :: FS | eff) (Either String FilePath)
142+
realpath' :: forall eff cache. FilePath -> { | cache } -> Eff (fs :: FS | eff) (Either Error FilePath)
143143

144-
rename :: forall eff. FilePath -> FilePath -> Eff (fs :: FS | eff) (Either String Unit)
144+
rename :: forall eff. FilePath -> FilePath -> Eff (fs :: FS | eff) (Either Error Unit)
145145

146-
rmdir :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either String Unit)
146+
rmdir :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either Error Unit)
147147

148-
stat :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either String Stats)
148+
stat :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either Error Stats)
149149

150-
symlink :: forall eff. FilePath -> FilePath -> SymlinkType -> Eff (fs :: FS | eff) (Either String Unit)
150+
symlink :: forall eff. FilePath -> FilePath -> SymlinkType -> Eff (fs :: FS | eff) (Either Error Unit)
151151

152-
truncate :: forall eff. FilePath -> Number -> Eff (fs :: FS | eff) (Either String Unit)
152+
truncate :: forall eff. FilePath -> Number -> Eff (fs :: FS | eff) (Either Error Unit)
153153

154-
unlink :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either String Unit)
154+
unlink :: forall eff. FilePath -> Eff (fs :: FS | eff) (Either Error Unit)
155155

156-
utimes :: forall eff. FilePath -> Date -> Date -> Eff (fs :: FS | eff) (Either String Unit)
156+
utimes :: forall eff. FilePath -> Date -> Date -> Eff (fs :: FS | eff) (Either Error Unit)
157157

158-
writeFile :: forall eff. FilePath -> Buffer -> Eff (fs :: FS | eff) (Either String Unit)
158+
writeFile :: forall eff. FilePath -> Buffer -> Eff (fs :: FS | eff) (Either Error Unit)
159159

160-
writeTextFile :: forall eff. Encoding -> FilePath -> String -> Eff (fs :: FS | eff) (Either String Unit)
160+
writeTextFile :: forall eff. Encoding -> FilePath -> String -> Eff (fs :: FS | eff) (Either Error Unit)

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"purescript-foreign": ">=0.1.1",
2424
"purescript-node-buffer": "*",
2525
"purescript-node-path": ">=0.1.0",
26-
"purescript-globals": ">=0.1.3",
26+
"purescript-globals": ">=0.1.4",
2727
"purescript-datetime": "*"
2828
}
2929
}

examples/Test.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ main = do
2424
S.rename "tmp\\Test.js" "tmp\\Test1.js"
2525

2626
S.truncate "tmp\\Test1.js" 1000
27-
27+
2828
stats <- S.stat "tmp\\Test1.js"
2929
case stats of
3030
Right stats' -> do
@@ -52,19 +52,19 @@ main = do
5252

5353
A.rename "tmp\\Test1.js" "tmp\\Test.js" $ \x -> do
5454
trace "\n\nrename result:"
55-
either trace' (trace' <<< show) x
55+
either (trace' <<< show) (trace' <<< show) x
5656

5757
A.truncate "tmp\\Test.js" 10 $ \x -> do
5858
trace "\n\ntruncate result:"
59-
either trace' (trace' <<< show) x
59+
either (trace' <<< show) (trace' <<< show) x
6060

6161
A.readFile "examples\\Test.purs" $ \x -> do
6262
trace "\n\nreadFile result:"
63-
either trace' (trace' <<< show) x
63+
either (trace' <<< show) (trace' <<< show) x
6464

6565
A.readTextFile UTF8 "examples\\Test.purs" $ \x -> do
6666
trace "\n\nreadTextFile result:"
67-
either trace' trace' x
67+
either (trace' <<< show) trace' x
6868

6969
A.stat "examples\\Test.purs" $ \x -> do
7070
trace "\n\nstat:"

src/Node/FS/Async.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import Node.Encoding
3535
import Node.FS
3636
import Node.FS.Stats
3737
import Node.Path (FilePath())
38-
import Global (Error(..))
38+
import Global (Error(), error)
3939

4040
type JSCallback a = Fn2 Foreign a Unit
4141

@@ -46,8 +46,8 @@ foreign import runCallbackEff
4646

4747
handleCallback :: forall eff a b. (Callback eff a) -> JSCallback a
4848
handleCallback f = mkFn2 $ \err x -> runCallbackEff $ f case parseForeign read err of
49-
Left err -> Left $ "handleCallback failed: " ++ err
50-
Right (Just err') -> Left $ show (err' :: Error)
49+
Left err -> Left $ error $ "handleCallback failed: " ++ show err
50+
Right (Just err') -> Left err'
5151
Right Nothing -> Right x
5252

5353
foreign import fs "var fs = require('fs');" ::
@@ -73,7 +73,7 @@ foreign import fs "var fs = require('fs');" ::
7373
-- |
7474
-- Type synonym for callback functions.
7575
--
76-
type Callback eff a = Either String a -> Eff eff Unit
76+
type Callback eff a = Either Error a -> Eff eff Unit
7777

7878
-- |
7979
-- Renames a file.

src/Node/FS/Sync.purs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ foreign import mkFSAction
6767
\ };\
6868
\ };\
6969
\ };\
70-
\}" :: forall eff a. (String -> Either String a)
71-
-> (a -> Either String a)
70+
\}" :: forall eff a. (Error -> Either Error a)
71+
-> (a -> Either Error a)
7272
-> (Unit -> a)
73-
-> Eff eff (Either String a)
73+
-> Eff eff (Either Error a)
7474

7575
-- |
7676
-- Renames a file.
7777
--
7878
rename :: forall eff. FilePath
7979
-> FilePath
80-
-> Eff (fs :: FS | eff) (Either String Unit)
80+
-> Eff (fs :: FS | eff) (Either Error Unit)
8181

8282
rename oldFile newFile = mkFSAction Left Right $ \_ -> runFn2
8383
fs.renameSync oldFile newFile
@@ -87,7 +87,7 @@ rename oldFile newFile = mkFSAction Left Right $ \_ -> runFn2
8787
--
8888
truncate :: forall eff. FilePath
8989
-> Number
90-
-> Eff (fs :: FS | eff) (Either String Unit)
90+
-> Eff (fs :: FS | eff) (Either Error Unit)
9191

9292
truncate file len = mkFSAction Left Right $ \_ -> runFn2
9393
fs.truncateSync file len
@@ -98,7 +98,7 @@ truncate file len = mkFSAction Left Right $ \_ -> runFn2
9898
chown :: forall eff. FilePath
9999
-> Number
100100
-> Number
101-
-> Eff (fs :: FS | eff) (Either String Unit)
101+
-> Eff (fs :: FS | eff) (Either Error Unit)
102102

103103
chown file uid gid = mkFSAction Left Right $ \_ -> runFn3
104104
fs.chownSync file uid gid
@@ -108,7 +108,7 @@ chown file uid gid = mkFSAction Left Right $ \_ -> runFn3
108108
--
109109
chmod :: forall eff. FilePath
110110
-> Number
111-
-> Eff (fs :: FS | eff) (Either String Unit)
111+
-> Eff (fs :: FS | eff) (Either Error Unit)
112112

113113
chmod file mode = mkFSAction Left Right $ \_ -> runFn2
114114
fs.chmodSync file mode
@@ -117,7 +117,7 @@ chmod file mode = mkFSAction Left Right $ \_ -> runFn2
117117
-- Gets file statistics.
118118
--
119119
stat :: forall eff. FilePath
120-
-> Eff (fs :: FS | eff) (Either String Stats)
120+
-> Eff (fs :: FS | eff) (Either Error Stats)
121121

122122
stat file = mkFSAction Left Right $ \_ -> Stats $ runFn1
123123
fs.statSync file
@@ -127,7 +127,7 @@ stat file = mkFSAction Left Right $ \_ -> Stats $ runFn1
127127
--
128128
link :: forall eff. FilePath
129129
-> FilePath
130-
-> Eff (fs :: FS | eff) (Either String Unit)
130+
-> Eff (fs :: FS | eff) (Either Error Unit)
131131

132132
link src dst = mkFSAction Left Right $ \_ -> runFn2
133133
fs.linkSync src dst
@@ -138,7 +138,7 @@ link src dst = mkFSAction Left Right $ \_ -> runFn2
138138
symlink :: forall eff. FilePath
139139
-> FilePath
140140
-> SymlinkType
141-
-> Eff (fs :: FS | eff) (Either String Unit)
141+
-> Eff (fs :: FS | eff) (Either Error Unit)
142142

143143
symlink src dst ty = mkFSAction Left Right $ \_ -> runFn3
144144
fs.symlinkSync src dst (show ty)
@@ -147,7 +147,7 @@ symlink src dst ty = mkFSAction Left Right $ \_ -> runFn3
147147
-- Reads the value of a symlink.
148148
--
149149
readlink :: forall eff. FilePath
150-
-> Eff (fs :: FS | eff) (Either String FilePath)
150+
-> Eff (fs :: FS | eff) (Either Error FilePath)
151151

152152
readlink path = mkFSAction Left Right $ \_ -> runFn1
153153
fs.readlinkSync path
@@ -156,7 +156,7 @@ readlink path = mkFSAction Left Right $ \_ -> runFn1
156156
-- Find the canonicalized absolute location for a path.
157157
--
158158
realpath :: forall eff. FilePath
159-
-> Eff (fs :: FS | eff) (Either String FilePath)
159+
-> Eff (fs :: FS | eff) (Either Error FilePath)
160160

161161
realpath path = mkFSAction Left Right $ \_ -> runFn2
162162
fs.realpathSync path {}
@@ -167,7 +167,7 @@ realpath path = mkFSAction Left Right $ \_ -> runFn2
167167
--
168168
realpath' :: forall eff cache. FilePath
169169
-> { | cache }
170-
-> Eff (fs :: FS | eff) (Either String FilePath)
170+
-> Eff (fs :: FS | eff) (Either Error FilePath)
171171

172172
realpath' path cache = mkFSAction Left Right $ \_ -> runFn2
173173
fs.realpathSync path cache
@@ -176,7 +176,7 @@ realpath' path cache = mkFSAction Left Right $ \_ -> runFn2
176176
-- Deletes a file.
177177
--
178178
unlink :: forall eff. FilePath
179-
-> Eff (fs :: FS | eff) (Either String Unit)
179+
-> Eff (fs :: FS | eff) (Either Error Unit)
180180

181181
unlink file = mkFSAction Left Right $ \_ -> runFn1
182182
fs.unlinkSync file
@@ -185,7 +185,7 @@ unlink file = mkFSAction Left Right $ \_ -> runFn1
185185
-- Deletes a directory.
186186
--
187187
rmdir :: forall eff. FilePath
188-
-> Eff (fs :: FS | eff) (Either String Unit)
188+
-> Eff (fs :: FS | eff) (Either Error Unit)
189189

190190
rmdir file = mkFSAction Left Right $ \_ -> runFn1
191191
fs.rmdirSync file
@@ -194,7 +194,7 @@ rmdir file = mkFSAction Left Right $ \_ -> runFn1
194194
-- Makes a new directory.
195195
--
196196
mkdir :: forall eff. FilePath
197-
-> Eff (fs :: FS | eff) (Either String Unit)
197+
-> Eff (fs :: FS | eff) (Either Error Unit)
198198

199199
mkdir = flip mkdir' 777
200200

@@ -203,7 +203,7 @@ mkdir = flip mkdir' 777
203203
--
204204
mkdir' :: forall eff. FilePath
205205
-> Number
206-
-> Eff (fs :: FS | eff) (Either String Unit)
206+
-> Eff (fs :: FS | eff) (Either Error Unit)
207207

208208
mkdir' file mode = mkFSAction Left Right $ \_ -> runFn2
209209
fs.mkdirSync file mode
@@ -212,7 +212,7 @@ mkdir' file mode = mkFSAction Left Right $ \_ -> runFn2
212212
-- Reads the contents of a directory.
213213
--
214214
readdir :: forall eff. FilePath
215-
-> Eff (fs :: FS | eff) (Either String [FilePath])
215+
-> Eff (fs :: FS | eff) (Either Error [FilePath])
216216

217217
readdir file = mkFSAction Left Right $ \_ -> runFn1
218218
fs.readdirSync file
@@ -223,7 +223,7 @@ readdir file = mkFSAction Left Right $ \_ -> runFn1
223223
utimes :: forall eff. FilePath
224224
-> Date
225225
-> Date
226-
-> Eff (fs :: FS | eff) (Either String Unit)
226+
-> Eff (fs :: FS | eff) (Either Error Unit)
227227

228228
utimes file atime mtime = mkFSAction Left Right $ \_ -> runFn3
229229
fs.utimesSync file
@@ -234,7 +234,7 @@ utimes file atime mtime = mkFSAction Left Right $ \_ -> runFn3
234234
-- Reads the entire contents of a file returning the result as a raw buffer.
235235
--
236236
readFile :: forall eff. FilePath
237-
-> Eff (fs :: FS | eff) (Either String Buffer)
237+
-> Eff (fs :: FS | eff) (Either Error Buffer)
238238

239239
readFile file = mkFSAction Left Right $ \_ -> runFn2
240240
fs.readFileSync file {}
@@ -244,7 +244,7 @@ readFile file = mkFSAction Left Right $ \_ -> runFn2
244244
--
245245
readTextFile :: forall eff. Encoding
246246
-> FilePath
247-
-> Eff (fs :: FS | eff) (Either String String)
247+
-> Eff (fs :: FS | eff) (Either Error String)
248248

249249
readTextFile encoding file = mkFSAction Left Right $ \_ -> runFn2
250250
fs.readFileSync file { encoding: show encoding }
@@ -254,7 +254,7 @@ readTextFile encoding file = mkFSAction Left Right $ \_ -> runFn2
254254
--
255255
writeFile :: forall eff. FilePath
256256
-> Buffer
257-
-> Eff (fs :: FS | eff) (Either String Unit)
257+
-> Eff (fs :: FS | eff) (Either Error Unit)
258258

259259
writeFile file buff = mkFSAction Left Right $ \_ -> runFn3
260260
fs.writeFileSync file buff {}
@@ -265,7 +265,7 @@ writeFile file buff = mkFSAction Left Right $ \_ -> runFn3
265265
writeTextFile :: forall eff. Encoding
266266
-> FilePath
267267
-> String
268-
-> Eff (fs :: FS | eff) (Either String Unit)
268+
-> Eff (fs :: FS | eff) (Either Error Unit)
269269

270270
writeTextFile encoding file buff = mkFSAction Left Right $ \_ -> runFn3
271271
fs.writeFileSync file buff { encoding: show encoding }
@@ -275,7 +275,7 @@ writeTextFile encoding file buff = mkFSAction Left Right $ \_ -> runFn3
275275
--
276276
appendFile :: forall eff. FilePath
277277
-> Buffer
278-
-> Eff (fs :: FS | eff) (Either String Unit)
278+
-> Eff (fs :: FS | eff) (Either Error Unit)
279279

280280
appendFile file buff = mkFSAction Left Right $ \_ -> runFn3
281281
fs.appendFileSync file buff {}
@@ -286,7 +286,7 @@ appendFile file buff = mkFSAction Left Right $ \_ -> runFn3
286286
appendTextFile :: forall eff. Encoding
287287
-> FilePath
288288
-> String
289-
-> Eff (fs :: FS | eff) (Either String Unit)
289+
-> Eff (fs :: FS | eff) (Either Error Unit)
290290

291291
appendTextFile encoding file buff = mkFSAction Left Right $ \_ -> runFn3
292292
fs.appendFileSync file buff { encoding: show encoding }

0 commit comments

Comments
 (0)