Skip to content

Commit bbe8595

Browse files
committed
update readme
1 parent 3fd134d commit bbe8595

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ import type { Result } from "ts-explicit-errors"
6969
import { attempt, err, isErr } from "ts-explicit-errors"
7070

7171
function getConfig(): Result<string> {
72-
const config = attempt(() => fs.readFileSync("config.json"))
73-
if (isErr(config)) return err("failed to read config file", config)
72+
const rawConfig = attempt(() => fs.readFileSync("config.json"))
73+
if (isErr(rawConfig)) return err("failed to read config file", rawConfig)
7474

75-
// you would probably parse the config here
75+
const parsedConfig = attempt(() => JSON.parse(rawConfig))
76+
if (isErr(parsedConfig)) return err("failed to parse config", parsedConfig)
7677

77-
return config
78+
return parsedConfig
7879
}
7980
```
8081

@@ -85,7 +86,9 @@ At some point, you'll want to handle the error chain. Use `messageChain` to log
8586

8687
const config = getConfig()
8788
if (isErr(config)) {
88-
console.error(config.messageChain) // failed to read config file -> ENOENT: no such file or directory, open 'config.json'
89+
console.error(config.messageChain)
90+
// (if 'fs.readFileSync' failed): failed to read config file -> ENOENT: no such file or directory, open 'config.json'
91+
// (if 'JSON.parse' failed): failed to parse config -> SyntaxError: JSON Parse error
8992
process.exit(1)
9093
}
9194

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy