Skip to content
This repository was archived by the owner on Aug 17, 2019. It is now read-only.

Commit 8916069

Browse files
committed
Fix bug with previous commit
1 parent 39f0a20 commit 8916069

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/main/scala/com/ckkloverdos/props/Props.scala

+17-17
Original file line numberDiff line numberDiff line change
@@ -44,127 +44,127 @@ class Props(val map: Map[String, String])(implicit conv: Converters = Converters
4444

4545
def getBoolean(key: String): Maybe[Boolean] = map.get(key) match {
4646
case Some(value)
47-
handleKeyError(key, conv.convertToBoolean(value))
47+
handleKeyLookup(key, conv.convertToBoolean(value))
4848

4949
case None
5050
NoVal
5151
}
5252

5353
def getBooleanEx(key: String): Boolean = map.get(key) match {
5454
case Some(value)
55-
handleKeyError(key, conv.convertToBooleanEx(value))
55+
handleKeyLookupEx(key, conv.convertToBooleanEx(value))
5656

5757
case None
5858
throw new IllegalArgumentException("Unknown key %s".format(key))
5959
}
6060

6161
def getByte(key: String): Maybe[Byte] = map.get(key) match {
6262
case Some(value)
63-
handleKeyError(key, conv.convertToByte(value))
63+
handleKeyLookup(key, conv.convertToByte(value))
6464

6565
case None
6666
NoVal
6767
}
6868

6969
def getByteEx(key: String): Byte = map.get(key) match {
7070
case Some(value)
71-
handleKeyError(key, conv.convertToByteEx(value))
71+
handleKeyLookupEx(key, conv.convertToByteEx(value))
7272

7373
case None
7474
throw new IllegalArgumentException("Unknown key %s".format(key))
7575
}
7676

7777
def getShort(key: String): Maybe[Short] = map.get(key) match {
7878
case Some(value)
79-
handleKeyError(key, conv.convertToShort(value))
79+
handleKeyLookup(key, conv.convertToShort(value))
8080

8181
case None
8282
NoVal
8383
}
8484

8585
def getShortEx(key: String): Short = map.get(key) match {
8686
case Some(value)
87-
handleKeyError(key, conv.convertToShortEx(value))
87+
handleKeyLookupEx(key, conv.convertToShortEx(value))
8888

8989
case None
9090
throw new IllegalArgumentException("Unknown key %s".format(key))
9191
}
9292

9393
def getInt(key: String): Maybe[Int] = map.get(key) match {
9494
case Some(value)
95-
handleKeyError(key, conv.convertToInt(value))
95+
handleKeyLookup(key, conv.convertToInt(value))
9696

9797
case None
9898
NoVal
9999
}
100100

101101
def getIntEx(key: String): Int = map.get(key) match {
102102
case Some(value)
103-
handleKeyError(key, conv.convertToIntEx(value))
103+
handleKeyLookupEx(key, conv.convertToIntEx(value))
104104

105105
case None
106106
throw new IllegalArgumentException("Unknown key %s".format(key))
107107
}
108108

109109
def getLong(key: String): Maybe[Long] = map.get(key) match {
110110
case Some(value)
111-
handleKeyError(key, conv.convertToLong(value))
111+
handleKeyLookup(key, conv.convertToLong(value))
112112

113113
case None
114114
NoVal
115115
}
116116

117117
def getLongEx(key: String): Long = map.get(key) match {
118118
case Some(value)
119-
handleKeyError(key, conv.convertToLongEx(value))
119+
handleKeyLookupEx(key, conv.convertToLongEx(value))
120120

121121
case None
122122
throw new IllegalArgumentException("Unknown key %s".format(key))
123123
}
124124

125125
def getDouble(key: String): Maybe[Double] = map.get(key) match {
126126
case Some(value)
127-
handleKeyError(key, conv.convertToDouble(value))
127+
handleKeyLookup(key, conv.convertToDouble(value))
128128

129129
case None
130130
NoVal
131131
}
132132

133133
def getDoubleEx(key: String): Double = map.get(key) match {
134134
case Some(value)
135-
handleKeyError(key, conv.convertToDoubleEx(value))
135+
handleKeyLookupEx(key, conv.convertToDoubleEx(value))
136136

137137
case None
138138
throw new IllegalArgumentException("Unknown key %s".format(key))
139139
}
140140

141141
def getFloat(key: String): Maybe[Float] = map.get(key) match {
142142
case Some(value)
143-
handleKeyError(key, conv.convertToFloat(value))
143+
handleKeyLookup(key, conv.convertToFloat(value))
144144

145145
case None
146146
NoVal
147147
}
148148

149149
def getFloatEx(key: String): Float = map.get(key) match {
150150
case Some(value)
151-
handleKeyError(key, conv.convertToFloatEx(value))
151+
handleKeyLookupEx(key, conv.convertToFloatEx(value))
152152

153153
case None
154154
throw new IllegalArgumentException("Unknown key %s".format(key))
155155
}
156156

157157
def getProps(key: String): Maybe[Props] = map.get(key) match {
158158
case Some(value)
159-
handleKeyError(key, conv.convert[Props](value))
159+
handleKeyLookup(key, conv.convert[Props](value))
160160

161161
case None
162162
NoVal
163163
}
164164

165165
def getPropsEx(key: String): Props = map.get(key) match {
166166
case Some(value)
167-
handleKeyError(key, conv.convertEx[Props](value))
167+
handleKeyLookupEx(key, conv.convertEx[Props](value))
168168

169169
case None
170170
throw new IllegalArgumentException("Unknown key %s".format(key))
@@ -173,7 +173,7 @@ class Props(val map: Map[String, String])(implicit conv: Converters = Converters
173173

174174
def getList(key: String, separatorRegex: String = "\\s*,\\s*") = map.get(key) match {
175175
case Some(value)
176-
handleKeyError(key, value.split(separatorRegex).toList)
176+
handleKeyLookupEx(key, value.split(separatorRegex).toList)
177177

178178
case None
179179
Nil

src/main/scala/com/ckkloverdos/props/PropsBase.scala

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.ckkloverdos.props
1818

1919
import com.ckkloverdos.convert.Converters
20-
import com.ckkloverdos.maybe.Maybe
20+
import com.ckkloverdos.maybe.{Failed, MaybeEither, Maybe}
2121

2222

2323
/**
@@ -63,7 +63,17 @@ trait PropsBase[K, V, P <: PropsBase[K, V, P]] {
6363

6464
def isEmpty = size == 0
6565

66-
protected[this] def handleKeyError[A](key: String, f: A): A = {
66+
protected[this] def handleKeyLookup[A](key: String, f: MaybeEither[A]): MaybeEither[A] = {
67+
f match {
68+
case Failed(e)
69+
Failed(new Exception("For key %s".format(key), e))
70+
71+
case just
72+
just
73+
}
74+
}
75+
76+
protected[this] def handleKeyLookupEx[A](key: String, f: A): A = {
6777
try f
6878
catch {
6979
case e: Throwable

0 commit comments

Comments
 (0)