Skip to content

Commit

Permalink
fix: defensive code around container logic (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
btkostner authored Jun 5, 2023
1 parent 03b55c3 commit 97d770b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/datadog/data_streams/container.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Datadog.DataStreams.Container do
file
|> File.stream!()
|> parse_container_id()
catch
rescue
_ -> nil
end

Expand All @@ -61,7 +61,7 @@ defmodule Datadog.DataStreams.Container do
|> Stream.map(&parse_line/1)
|> Stream.filter(fn value -> not is_nil(value) end)
|> Enum.at(0)
catch
rescue
_ -> nil
end

Expand Down
4 changes: 4 additions & 0 deletions test/datadog/data_streams/container_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,8 @@ defmodule Datadog.DataStreams.ContainerTest do

assert ^cid = Container.read_container_id(file_path)
end

test "read_container_id/1 does not fail when file does not exist" do
refute Container.read_container_id("/does/not/exist/ohpleasedontbreakmytests")
end
end

0 comments on commit 97d770b

Please sign in to comment.