Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 1040676

Browse files
Set env correctly (fixing Vapor bug)
1 parent 589e80e commit 1040676

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Sources/Bugsnag/Provider.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,33 @@ public final class Provider: Vapor.Provider {
1515
public func boot(_ config: Config) throws {
1616
try config.addConfigurable(middleware: Middleware(config: config), name: "bugsnag")
1717

18-
guard let config: Config = config["bugsnag"] else {
18+
guard let bConfig: Config = config["bugsnag"] else {
1919
throw Abort(
2020
.internalServerError,
2121
reason: "Bugsnag error - bugsnag.json config is missing."
2222
)
2323
}
2424

25-
self.config = try BugsnagConfig(config)
25+
// NOTE: there is a bug in Vapor where extracted configs don't have the
26+
// same environment as the root config
27+
bConfig.environment = config.environment
28+
self.config = try BugsnagConfig(bConfig)
2629
}
2730

2831
public init(config: Config) throws {
2932
try config.addConfigurable(middleware: Middleware(config: config), name: "bugsnag")
3033

31-
guard let config: Config = config["bugsnag"] else {
34+
guard let bConfig: Config = config["bugsnag"] else {
3235
throw Abort(
3336
.internalServerError,
3437
reason: "Bugsnag error - bugsnag.json config is missing."
3538
)
3639
}
3740

38-
self.config = try BugsnagConfig(config)
41+
// NOTE: there is a bug in Vapor where extracted configs don't have the
42+
// same environment as the root config
43+
bConfig.environment = config.environment
44+
self.config = try BugsnagConfig(bConfig)
3945
}
4046

4147
// is automatically called directly after boot()

Sources/Bugsnag/ReporterFactory.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import Stacked
33

44
public struct ReporterFactory {
55
public static func make(config: Config) throws -> Reporter {
6-
guard let config: Config = config["bugsnag"] else {
6+
guard let bConfig: Config = config["bugsnag"] else {
77
throw Abort(
88
.internalServerError,
99
reason: "Bugsnag error - bugsnag.json config is missing."
1010
)
1111
}
1212

13-
let bugsnagConfig = try BugsnagConfig(config)
13+
// NOTE: there is a bug in Vapor where extracted configs don't have the
14+
// same environment as the root config
15+
bConfig.environment = config.environment
16+
let bugsnagConfig = try BugsnagConfig(bConfig)
1417
return ReporterFactory.make(bugsnagConfig: bugsnagConfig)
1518
}
1619

0 commit comments

Comments
 (0)