From 3e8fc1c2bc17935cb7d9a97842653ded7635d282 Mon Sep 17 00:00:00 2001 From: Frank Hunleth Date: Tue, 9 May 2023 19:11:35 -0400 Subject: [PATCH] Add guards to prevent commandline accidents from propagating --- lib/ring_logger/autoclient.ex | 12 ++++++------ lib/ring_logger/client.ex | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ring_logger/autoclient.ex b/lib/ring_logger/autoclient.ex index 1ee419c..84520f2 100644 --- a/lib/ring_logger/autoclient.ex +++ b/lib/ring_logger/autoclient.ex @@ -13,7 +13,7 @@ defmodule RingLogger.Autoclient do Attach to the logger and print messages as they come in. """ @spec attach(RingLogger.client_options()) :: :ok | {:error, term()} - def attach(opts \\ []) do + def attach(opts \\ []) when is_list(opts) do run(&Client.attach/1, opts) end @@ -54,7 +54,7 @@ defmodule RingLogger.Autoclient do Print the log messages since the previous time this was called. """ @spec next(RingLogger.client_options()) :: :ok | {:error, term()} - def next(opts \\ []) do + def next(opts \\ []) when is_list(opts) do run(&Client.next(&1, opts), opts) end @@ -62,7 +62,7 @@ defmodule RingLogger.Autoclient do Print the log message count since the previous time this was called. """ @spec count_next(RingLogger.client_options()) :: non_neg_integer() - def count_next(opts \\ []) do + def count_next(opts \\ []) when is_list(opts) do run(&Client.count_next/1, opts) end @@ -70,7 +70,7 @@ defmodule RingLogger.Autoclient do Print the most recent log messages. """ @spec tail(non_neg_integer(), RingLogger.client_options()) :: :ok - def tail(n, opts) do + def tail(n, opts) when is_integer(n) and is_list(opts) do run(&Client.tail(&1, n, opts), opts) end @@ -78,7 +78,7 @@ defmodule RingLogger.Autoclient do Run a regular expression on each entry in the log and print out the matchers. """ @spec grep(String.t() | Regex.t(), RingLogger.client_options()) :: :ok | {:error, term()} - def grep(regex_or_string, opts \\ []) do + def grep(regex_or_string, opts \\ []) when is_list(opts) do run(&Client.grep(&1, regex_or_string, opts), opts) end @@ -87,7 +87,7 @@ defmodule RingLogger.Autoclient do that the next call to `tail/1` starts back at the oldest entry. """ @spec reset(RingLogger.client_options()) :: :ok | {:error, term()} - def reset(opts \\ []) do + def reset(opts \\ []) when is_list(opts) do run(&Client.reset/1, opts) end diff --git a/lib/ring_logger/client.ex b/lib/ring_logger/client.ex index 8043856..375a976 100644 --- a/lib/ring_logger/client.ex +++ b/lib/ring_logger/client.ex @@ -64,7 +64,7 @@ defmodule RingLogger.Client do will take precedence. """ @spec configure(GenServer.server(), RingLogger.client_options()) :: :ok - def configure(client_pid, config) do + def configure(client_pid, config) when is_list(config) do GenServer.call(client_pid, {:configure, config}) end