Skip to content

Commit 820e5f8

Browse files
committed
switch from error to fail in binary decoders
1 parent 221c71e commit 820e5f8

File tree

7 files changed

+22
-23
lines changed

7 files changed

+22
-23
lines changed

builder/src/Elm/Details.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ instance Binary ValidOutline where
776776
case n of
777777
0 -> liftM ValidApp get
778778
1 -> liftM3 ValidPkg get get get
779-
_ -> error "binary encoding of ValidOutline was corrupted"
779+
_ -> fail "binary encoding of ValidOutline was corrupted"
780780

781781

782782
instance Binary Local where

compiler/src/AST/Canonical.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ instance Binary CtorOpts where
342342
0 -> return Normal
343343
1 -> return Enum
344344
2 -> return Unbox
345-
_ -> error "binary encoding of CtorOpts was corrupted"
345+
_ -> fail "binary encoding of CtorOpts was corrupted"
346346

347347

348348
instance Binary Annotation where
@@ -393,7 +393,7 @@ instance Binary AliasType where
393393
case n of
394394
0 -> liftM Holey get
395395
1 -> liftM Filled get
396-
_ -> error "binary encoding of AliasType was corrupted"
396+
_ -> fail "binary encoding of AliasType was corrupted"
397397

398398

399399
instance Binary FieldType where

compiler/src/AST/Optimized.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ instance Binary Expr where
308308
24 -> pure Unit
309309
25 -> liftM3 Tuple get get get
310310
26 -> liftM3 Shader get get get
311-
_ -> error "problem getting Opt.Expr binary"
311+
_ -> fail "problem getting Opt.Expr binary"
312312

313313

314314
instance Binary Def where
@@ -322,7 +322,7 @@ instance Binary Def where
322322
case word of
323323
0 -> liftM2 Def get get
324324
1 -> liftM3 TailDef get get get
325-
_ -> error "problem getting Opt.Def binary"
325+
_ -> fail "problem getting Opt.Def binary"
326326

327327

328328
instance Binary Destructor where
@@ -345,7 +345,7 @@ instance Binary Path where
345345
1 -> liftM2 Field get get
346346
2 -> liftM Unbox get
347347
3 -> liftM Root get
348-
_ -> error "problem getting Opt.Path binary"
348+
_ -> fail "problem getting Opt.Path binary"
349349

350350

351351
instance (Binary a) => Binary (Decider a) where
@@ -361,7 +361,7 @@ instance (Binary a) => Binary (Decider a) where
361361
0 -> liftM Leaf get
362362
1 -> liftM3 Chain get get get
363363
2 -> liftM3 FanOut get get get
364-
_ -> error "problem getting Opt.Decider binary"
364+
_ -> fail "problem getting Opt.Decider binary"
365365

366366

367367
instance Binary Choice where
@@ -375,7 +375,7 @@ instance Binary Choice where
375375
case word of
376376
0 -> liftM Inline get
377377
1 -> liftM Jump get
378-
_ -> error "problem getting Opt.Choice binary"
378+
_ -> fail "problem getting Opt.Choice binary"
379379

380380

381381

@@ -400,7 +400,7 @@ instance Binary Main where
400400
case word of
401401
0 -> return Static
402402
1 -> liftM2 Dynamic get get
403-
_ -> error "problem getting Opt.Main binary"
403+
_ -> fail "problem getting Opt.Main binary"
404404

405405

406406
instance Binary Node where
@@ -432,7 +432,7 @@ instance Binary Node where
432432
8 -> liftM2 Kernel get get
433433
9 -> liftM2 PortIncoming get get
434434
10 -> liftM2 PortOutgoing get get
435-
_ -> error "problem getting Opt.Node binary"
435+
_ -> fail "problem getting Opt.Node binary"
436436

437437

438438
instance Binary EffectsType where
@@ -448,4 +448,4 @@ instance Binary EffectsType where
448448
0 -> return Cmd
449449
1 -> return Sub
450450
2 -> return Fx
451-
_ -> error "problem getting Opt.EffectsType binary"
451+
_ -> fail "problem getting Opt.EffectsType binary"

compiler/src/AST/Utils/Binop.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ instance Binary Precedence where
4141
instance Binary Associativity where
4242
get =
4343
do n <- getWord8
44-
return $
45-
case n of
46-
0 -> Left
47-
1 -> Non
48-
2 -> Right
49-
_ -> error "Error reading valid associativity from serialized string"
44+
case n of
45+
0 -> return Left
46+
1 -> return Non
47+
2 -> return Right
48+
_ -> fail "Error reading valid associativity from serialized string"
5049

5150
put assoc =
5251
putWord8 $

compiler/src/Elm/Constraint.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ instance Binary Op where
216216
case n of
217217
0 -> return Less
218218
1 -> return LessOrEqual
219-
_ -> error "binary encoding of Op was corrupted"
219+
_ -> fail "binary encoding of Op was corrupted"
220220

221221

222222

compiler/src/Elm/Interface.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ instance Binary Union where
215215
0 -> liftM OpenUnion get
216216
1 -> liftM ClosedUnion get
217217
2 -> liftM PrivateUnion get
218-
_ -> error "binary encoding of Union was corrupted"
218+
_ -> fail "binary encoding of Union was corrupted"
219219

220220

221221
instance Binary Alias where
@@ -229,7 +229,7 @@ instance Binary Alias where
229229
case n of
230230
0 -> liftM PublicAlias get
231231
1 -> liftM PrivateAlias get
232-
_ -> error "binary encoding of Alias was corrupted"
232+
_ -> fail "binary encoding of Alias was corrupted"
233233

234234

235235
instance Binary Binop where
@@ -251,4 +251,4 @@ instance Binary DependencyInterface where
251251
case n of
252252
0 -> liftM Public get
253253
1 -> liftM3 Private get get get
254-
_ -> error "binary encoding of DependencyInterface was corrupted"
254+
_ -> fail "binary encoding of DependencyInterface was corrupted"

compiler/src/Optimize/DecisionTree.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ instance Binary Test where
618618
5 -> liftM IsStr get
619619
6 -> liftM IsInt get
620620
7 -> liftM IsBool get
621-
_ -> error "problem getting DecisionTree.Test binary"
621+
_ -> fail "problem getting DecisionTree.Test binary"
622622

623623

624624
instance Binary Path where
@@ -634,4 +634,4 @@ instance Binary Path where
634634
0 -> liftM2 Index get get
635635
1 -> liftM Unbox get
636636
2 -> pure Empty
637-
_ -> error "problem getting DecisionTree.Path binary"
637+
_ -> fail "problem getting DecisionTree.Path binary"

0 commit comments

Comments
 (0)