Github: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
- Dominant language
- Swift
- Stars
- 1.1k
- Forks
- 152
- Avg merge
- 9h 54m
- Merged PRs (30d)
- 2
Description
Hello,
In the last two weeks, we are seeing Danger failing on Bitrise with the following crash `Github: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value` and the code generating the crash is
```swift
static func validatePRDescription(using danger: DangerDSL) {
guard let description = danger.github.pullRequest.body, !description.isEmpty else { // Crash here due to nil danger.github value
danger.warn("Please provide a summary in the Pull Request description")
return
}
}
```
After some examination, we saw that in `DangerDSL.init(from:)` the Github object is initialized by decoding it if present (`github = try container.decodeIfPresent(GitHub.self, forKey: .github)`). This means that this line can return a nil value, while the GitHub property is forced unwrapped (`DangerDSL.getter:github`), which leads to a crash in our case.
Do you know why Github object fails to be initialized? Also, it wouldn't be better if CIs objects are optional, as each instance of Danger can in one CI only.
Note: The code above is part of [wetransfer CI OSS](https://github.com/WeTransfer/WeTransfer-iOS-CI) and with their mock Github [response](https://github.com/WeTransfer/WeTransfer-iOS-CI/blob/master/WeTransferPRLinter/Tests/WeTransferPRLinterTests/TestHelpers/TestGithubDSL.swift) everything works as expected. Maybe Github has changed their JSONs ?? 🤔
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.