-
Notifications
You must be signed in to change notification settings - Fork 0
/
throwError.ls
95 lines (48 loc) · 1.65 KB
/
throwError.ls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
FLYD_URL = "github.com/paldepind/flyd"
initial-utils = require "@sourcevault/initial.utils"
_ = require "ramda"
print = initial-utils.printError.create do
"flyd-until"
"github.com/sourcevault/flyd-until"
throwError = {}
throwError.not-flyd-stream = ->
color = print.getColor!
fs = color.highlight('flyd stream')
f = color.highlight('flyd')
err-text = """
- second argument (stream) is of wrong type.
- stream value should be a #{fs} object.
- more details on [#{f}] can be read at:
#{color.highlight(FLYD_URL)}
"""
print.throwTypeError err-text
expected-type = ["number", "positive", "integer" ]
andJoin = (list) ->
switch list.length
| 0 => ""
| 1 => list.join ""
| 2 =>
ret = list[0] + " and " + list[1]
ret
| otherwise =>
head = (_.init list) |> _.join ", "
tail = "and " + (_.last list)
head + " " + tail
throwError.amount-is-not-integer = (type) !->
color = print.getColor!
colorized-expected-type = _.map color.highlight,expected-type
expected-type-str = andJoin colorized-expected-type
des = type.getDes!
wrong-props = _.difference des,expected-type
correct-parts = _.intersection des,expected-type
correct-parts-str = des |> _.intersection expected-type |> _.map color.highlight
wrong-props-str = _.map color.attention1,wrong-props
colorized = _.concat wrong-props-str, correct-parts-str
unexpected-type-str = andJoin colorized
err-text = """
- first argument (amount) is of wrong type.
- amount value should be a #{expected-type-str}.
- current type is #{unexpected-type-str}.
"""
print.throwTypeError err-text
module.exports = throwError