Skip to content

Commit 4d0af16

Browse files
committed
Check if bytebuffer is empty before checking all variables for optionals
1 parent 6b39175 commit 4d0af16

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Sources/LoggingELK/LogstashLogHandler+Uploading.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,23 @@ extension LogstashLogHandler {
3333
/// for a short amount of time (the time it takes to duplicate this bytebuffer). Then, the "original"
3434
/// stored log data `ByteBuffer` is freed and the lock is lifted
3535
static func uploadLogData(_ task: RepeatedTask? = nil) { // swiftlint:disable:this cyclomatic_complexity function_body_length
36-
guard let _ = Self.byteBuffer,
37-
let _ = Self.totalByteBufferSize,
38-
let maximumTotalLogStorageSize = Self.maximumTotalLogStorageSize,
39-
let eventLoopGroup = Self.eventLoopGroup,
40-
let httpClient = Self.httpClient,
41-
let hostname = Self.hostname,
42-
let port = Self.port else {
36+
guard let _ = Self.byteBuffer else {
4337
fatalError(Error.notYetSetup.rawValue)
4438
}
4539

4640
guard Self.byteBuffer?.readableBytes != 0 else {
4741
return
4842
}
4943

44+
guard let _ = Self.totalByteBufferSize,
45+
let maximumTotalLogStorageSize = Self.maximumTotalLogStorageSize,
46+
let eventLoopGroup = Self.eventLoopGroup,
47+
let httpClient = Self.httpClient,
48+
let hostname = Self.hostname,
49+
let port = Self.port else {
50+
fatalError(Error.notYetSetup.rawValue)
51+
}
52+
5053
// If total byte buffer size is exceeded, wait until the size is decreased again
5154
if totalByteBufferSize! + Self.byteBuffer!.capacity > maximumTotalLogStorageSize {
5255
Self.semaphoreCounter -= 1

0 commit comments

Comments
 (0)