Skip to content

Add typespecs for public functions #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 11, 2024
Merged
9 changes: 9 additions & 0 deletions lib/error_tracker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ defmodule ErrorTracker do
"""
@type context :: %{String.t() => any()}

@typedoc """
An `Exception` or a `{kind, payload}` tuple compatible with `Exception.normalize/3`.
"""
@type exception :: Exception.t() | {:error, any()} | {Exception.non_error_kind(), any()}

import Ecto.Query

alias ErrorTracker.Error
Expand Down Expand Up @@ -107,6 +112,8 @@ defmodule ErrorTracker do
* A `{kind, exception}` tuple in which case the information is converted to
an Elixir exception (if possible) and stored.
"""

@spec report(exception(), Exception.stacktrace(), context()) :: Occurrence.t() | :noop
def report(exception, stacktrace, given_context \\ %{}) do
{kind, reason} = normalize_exception(exception, stacktrace)
{:ok, stacktrace} = ErrorTracker.Stacktrace.new(stacktrace)
Expand All @@ -127,6 +134,7 @@ defmodule ErrorTracker do
If an error is marked as resolved and it happens again, it will automatically
appear as unresolved again.
"""
@spec resolve(Error.t()) :: {:ok, Error.t()} | {:error, Ecto.Changeset.t()}
def resolve(error = %Error{status: :unresolved}) do
changeset = Ecto.Changeset.change(error, status: :resolved)

Expand All @@ -139,6 +147,7 @@ defmodule ErrorTracker do
@doc """
Marks an error as unresolved.
"""
@spec unresolve(Error.t()) :: {:ok, Error.t()} | {:error, Ecto.Changeset.t()}
def unresolve(error = %Error{status: :resolved}) do
changeset = Ecto.Changeset.change(error, status: :unresolved)

Expand Down
3 changes: 3 additions & 0 deletions lib/error_tracker/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ defmodule ErrorTracker.Migration do
@callback down(Keyword.t()) :: :ok
@callback current_version(Keyword.t()) :: non_neg_integer()

@spec up(Keyword.t()) :: :ok
def up(opts \\ []) when is_list(opts) do
migrator().up(opts)
end

@spec down(Keyword.t()) :: :ok
def down(opts \\ []) when is_list(opts) do
migrator().down(opts)
end

@spec migrated_version(Keyword.t()) :: non_neg_integer()
def migrated_version(opts \\ []) when is_list(opts) do
migrator().migrated_version(opts)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/error_tracker/schemas/error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ defmodule ErrorTracker.Error do

use Ecto.Schema

@type t :: %__MODULE__{}

schema "error_tracker_errors" do
field :kind, :string
field :reason, :string
Expand Down
5 changes: 4 additions & 1 deletion lib/error_tracker/schemas/occurrence.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ defmodule ErrorTracker.Occurrence do
in which the exception raised.
"""

import Ecto.Changeset

use Ecto.Schema

require Logger
import Ecto.Changeset

@type t :: %__MODULE__{}

schema "error_tracker_occurrences" do
field :context, :map
Expand Down
2 changes: 2 additions & 0 deletions lib/error_tracker/schemas/stacktrace.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ defmodule ErrorTracker.Stacktrace do

use Ecto.Schema

@type t :: %__MODULE__{}

@primary_key false
embedded_schema do
embeds_many :lines, Line, primary_key: false do
Expand Down