Skip to content

Commit

Permalink
Merge pull request #11 from invenia/rf/long-msgs
Browse files Browse the repository at this point in the history
Warn vs error on messages that are too long
  • Loading branch information
rofinn authored Apr 16, 2019
2 parents 0323eee + f2b0a6c commit 435ec82
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
julia 0.7
AWSCore 0.3
MbedTLS
Memento 0.9
Memento 0.12.1
Mocking 0.5.3
TimeZones 0.5
8 changes: 5 additions & 3 deletions src/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ struct LogEvent
end

if sizeof(message) > MAX_EVENT_SIZE - 26
throw(ArgumentError(
"Log Event message cannot be more than than $MAX_EVENT_SIZE bytes"
))
# Truncate message and throw a warning
idx = MAX_EVENT_SIZE - 29
# Truncated messages include a "..."
message = string(message[1:idx], "...")
warn(LOGGER, "CloudWatch Log Event message cannot be more than $MAX_EVENT_SIZE bytes")
end

if timestamp < 0
Expand Down
4 changes: 3 additions & 1 deletion test/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ end
@testset "Bad construction" begin
@test_throws ArgumentError LogEvent("")
@test_throws ArgumentError LogEvent("Foo", -45)
@test_throws ArgumentError LogEvent("A" ^ (CloudWatchLogs.MAX_EVENT_SIZE - 25))
@test_warn getlogger("CloudWatchLogs") "Log Event message cannot be more than" begin
LogEvent("A" ^ (MAX_EVENT_SIZE - 25))
end
end

end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Mocking
Mocking.enable(; force=true)

using CloudWatchLogs
using CloudWatchLogs: MAX_EVENT_SIZE

import AWSCore
import AWSCore.Services: logs, sts
Expand Down

0 comments on commit 435ec82

Please sign in to comment.