Skip to content

Commit 7fb2669

Browse files
committed
Improve the error messaging around the Environment bootstrap
1 parent 855bed7 commit 7fb2669

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strontium",
3-
"version": "2.7.3",
3+
"version": "2.7.4",
44
"description": "Strontium is a TypeScript toolkit for High Performance API servers built for Production not Projects.",
55
"main": "lib/src/index.js",
66
"types": "lib/src/index.d.ts",

src/bootstrap/drivers/Environment.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Container } from "inversify"
2+
import { Logger } from "../../logging";
23
import { Process } from "../../runtime"
34
import { ObjectValidator, ValidatedObject, isObject } from "../../validation"
45

@@ -26,7 +27,17 @@ export class Environment<O extends ObjectValidator> implements Process {
2627
public async startup(container: Container): Promise<void> {
2728
container.bind(Environment).toConstantValue(this)
2829

29-
this.validatedEnvironment = await isObject(this.validator)(process.env)
30+
try {
31+
this.validatedEnvironment = await isObject(this.validator)(process.env)
32+
} catch (e) {
33+
if (container.isBound(Logger)) {
34+
container.get(Logger).error("Environment validation failed!", e)
35+
} else {
36+
console.error(e)
37+
}
38+
39+
throw e
40+
}
3041
}
3142

3243
public async shutdown(container: Container): Promise<void> {

0 commit comments

Comments
 (0)