Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into refactor_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
melrief committed Mar 24, 2017
2 parents 868537e + 0528096 commit 58a5938
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 10 additions & 4 deletions docs/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ using the `ConfigReaderFailure` sealed family of case classes, you can use the
`ConfigValueLocation.apply(cv: ConfigValue)` method to automatically create an
optional location from a `ConfigValue`.

Given this setup:
If we load a config and try to load a missing key:

```scala
import com.typesafe.config._
import pureconfig.error._
import java.nio.file.{ Path, Paths }

val cv = ConfigFactory.load.root().get("conf")
val notFound = KeyNotFound("xpto", ConfigValueLocation(cv)).location.get
```

We can try to load a missing key and get a useful error:
We can extract useful error data:
```scala
KeyNotFound("xpto", ConfigValueLocation(cv))
// res1: pureconfig.error.KeyNotFound = KeyNotFound(xpto,Some(ConfigValueLocation(/Users/dvm105/pureconfig/docs/target/scala-2.12/classes/application.conf,11)))
// print the filename as a relative path
Paths.get(System.getProperty("user.dir")).relativize(Paths.get(notFound.url.toURI))
// res2: java.nio.file.Path = docs/target/scala-2.12/classes/application.conf

notFound.lineNumber
// res3: Int = 11
```
11 changes: 8 additions & 3 deletions docs/src/main/tut/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ using the `ConfigReaderFailure` sealed family of case classes, you can use the
`ConfigValueLocation.apply(cv: ConfigValue)` method to automatically create an
optional location from a `ConfigValue`.

Given this setup:
If we load a config and try to load a missing key:

```tut:silent
import com.typesafe.config._
import pureconfig.error._
import java.nio.file.{ Path, Paths }
val cv = ConfigFactory.load.root().get("conf")
val notFound = KeyNotFound("xpto", ConfigValueLocation(cv)).location.get
```

We can try to load a missing key and get a useful error:
We can extract useful error data:
```tut:book
KeyNotFound("xpto", ConfigValueLocation(cv))
// print the filename as a relative path
Paths.get(System.getProperty("user.dir")).relativize(Paths.get(notFound.url.toURI))
notFound.lineNumber
```

0 comments on commit 58a5938

Please sign in to comment.