Skip to content

Commit

Permalink
Modify ConfigValueLocation to use URL instead of String (#180)
Browse files Browse the repository at this point in the history
* Modify ConfigValueLocation to use Path

* Use URL instead of Path
  • Loading branch information
jcazevedo authored and melrief committed Mar 22, 2017
1 parent 721603b commit 9ee83e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
15 changes: 8 additions & 7 deletions core/src/main/scala/pureconfig/error/ConfigReaderFailure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package pureconfig.error

import java.net.URL

import com.typesafe.config.{ ConfigOrigin, ConfigValue }

/**
* The physical location of a ConfigValue, represented by a file name and a line
* The physical location of a ConfigValue, represented by a url and a line
* number
*
* @param filename the complete pathname to the file that contains a given
* ConfigValue
* @param url the URL describing the origin of the ConfigValue
* @param lineNumber the line number (starting at 0), where the given
* ConfigValue definition starts
*/
case class ConfigValueLocation(filename: String, lineNumber: Int) {
def description: String = s"($filename:$lineNumber)"
case class ConfigValueLocation(url: URL, lineNumber: Int) {
def description: String = s"($url:$lineNumber)"
}

object ConfigValueLocation {
Expand Down Expand Up @@ -48,8 +49,8 @@ object ConfigValueLocation {
*/
def apply(co: ConfigOrigin): Option[ConfigValueLocation] =
Option(co).flatMap { origin =>
if (origin.filename != null && origin.lineNumber != -1)
Some(ConfigValueLocation(origin.filename, origin.lineNumber))
if (origin.url != null && origin.lineNumber != -1)
Some(ConfigValueLocation(origin.url, origin.lineNumber))
else
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package pureconfig

import com.typesafe.config.ConfigFactory
import java.net.URL

import com.typesafe.config.ConfigFactory
import org.scalatest._

import pureconfig.error._

/**
Expand All @@ -22,23 +24,23 @@ class ConfigReaderFailureLocationSuite extends FlatSpec with Matchers with Eithe

val failures1 = conf.get("conf").to[Conf].left.value.toList
failures1 should have size 2
failures1 should contain(KeyNotFound("a", Some(ConfigValueLocation(workingDir + file, 1))))
failures1 should contain(KeyNotFound("a", Some(ConfigValueLocation(new URL("file", "", workingDir + file), 1))))
failures1 should contain(CannotConvert(
"hello",
"Int",
"""java.lang.NumberFormatException: For input string: "hello"""",
Some(ConfigValueLocation(workingDir + file, 3)),
Some(ConfigValueLocation(new URL("file", "", workingDir + file), 3)),
Some("c")))

val failures2 = conf.get("other-conf").to[Conf].left.value.toList
failures2 should have size 3
failures2 should contain(KeyNotFound("a", Some(ConfigValueLocation(workingDir + file, 7))))
failures2 should contain(KeyNotFound("b", Some(ConfigValueLocation(workingDir + file, 7))))
failures2 should contain(KeyNotFound("a", Some(ConfigValueLocation(new URL("file", "", workingDir + file), 7))))
failures2 should contain(KeyNotFound("b", Some(ConfigValueLocation(new URL("file", "", workingDir + file), 7))))
failures2 should contain(CannotConvert(
"hello",
"Int",
"""java.lang.NumberFormatException: For input string: "hello"""",
Some(ConfigValueLocation(workingDir + file, 9)),
Some(ConfigValueLocation(new URL("file", "", workingDir + file), 9)),
Some("c")))
}

Expand All @@ -57,7 +59,7 @@ class ConfigReaderFailureLocationSuite extends FlatSpec with Matchers with Eithe
"string",
"Int",
"""java.lang.NumberFormatException: For input string: "string"""",
Some(ConfigValueLocation(workingDir + file2, 2)),
Some(ConfigValueLocation(new URL("file", "", workingDir + file2), 2)),
Some("a")))
}
}

0 comments on commit 9ee83e2

Please sign in to comment.