From 8fae6836cdd60501d57b478fd29107e73718f372 Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Mon, 5 Jun 2023 15:28:44 -0600 Subject: [PATCH] fix: defensive code around container logic --- lib/datadog/data_streams/container.ex | 4 ++-- test/datadog/data_streams/container_test.exs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/datadog/data_streams/container.ex b/lib/datadog/data_streams/container.ex index 8fedd13..a17c472 100644 --- a/lib/datadog/data_streams/container.ex +++ b/lib/datadog/data_streams/container.ex @@ -49,7 +49,7 @@ defmodule Datadog.DataStreams.Container do file |> File.stream!() |> parse_container_id() - catch + rescue _ -> nil end @@ -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 diff --git a/test/datadog/data_streams/container_test.exs b/test/datadog/data_streams/container_test.exs index 5b49c71..2ff9973 100644 --- a/test/datadog/data_streams/container_test.exs +++ b/test/datadog/data_streams/container_test.exs @@ -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