Skip to content
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

Adding error return patterns to functions specs #342

Open
wants to merge 15 commits into
base: kobil
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dialyzer-ignore.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{":0:unknown_type Unknown type: Mongo.WriteError.t/0." }
]
hauleth marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 6 additions & 6 deletions lib/mongo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ defmodule Mongo do
* `:max_time` - Specifies a time limit in milliseconds
* `:use_cursor` - Use a cursor for a batched response (Default: true)
"""
@spec aggregate(GenServer.server(), collection, [BSON.document()], Keyword.t()) :: cursor
@spec aggregate(GenServer.server(), collection, [BSON.document()], Keyword.t()) :: cursor | {:error, Mongo.Error.t()}
hauleth marked this conversation as resolved.
Show resolved Hide resolved
def aggregate(topology_pid, coll, pipeline, opts \\ []) do
query =
[
Expand Down Expand Up @@ -482,7 +482,7 @@ defmodule Mongo do
* `:projection` - Limits the fields to return for all matching document
* `:skip` - The number of documents to skip before returning (Default: 0)
"""
@spec find(GenServer.server(), collection, BSON.document(), Keyword.t()) :: cursor
@spec find(GenServer.server(), collection, BSON.document(), Keyword.t()) :: cursor | {:error, Mongo.Error.t()}
def find(topology_pid, coll, filter, opts \\ []) do
query =
[
Expand Down Expand Up @@ -538,7 +538,7 @@ defmodule Mongo do
* `:skip` - The number of documents to skip before returning (Default: 0)
"""
@spec find_one(GenServer.server(), collection, BSON.document(), Keyword.t()) ::
BSON.document() | nil
BSON.document() | nil | {:error, Mongo.Error.t()}
def find_one(conn, coll, filter, opts \\ []) do
opts =
opts
Expand Down Expand Up @@ -1001,7 +1001,7 @@ defmodule Mongo do
@doc """
Returns a cursor to enumerate all indexes
"""
@spec list_indexes(GenServer.server(), String.t(), Keyword.t()) :: cursor
@spec list_indexes(GenServer.server(), String.t(), Keyword.t()) :: cursor | {:error, Mongo.Error.t()}
def list_indexes(topology_pid, coll, opts \\ []) do
with {:ok, conn, _, _} <- select_server(topology_pid, :read, opts) do
aggregation_cursor(conn, "$cmd", [listIndexes: coll], nil, opts)
Expand All @@ -1011,7 +1011,7 @@ defmodule Mongo do
@doc """
Convenient function that returns a cursor with the names of the indexes.
"""
@spec list_index_names(GenServer.server(), String.t(), Keyword.t()) :: %Stream{}
@spec list_index_names(GenServer.server(), String.t(), Keyword.t()) :: %Stream{} | {:error, Mongo.Error.t()}
def list_index_names(topology_pid, coll, opts \\ []) do
list_indexes(topology_pid, coll, opts)
|> Stream.map(fn %{"name" => name} -> name end)
Expand All @@ -1020,7 +1020,7 @@ defmodule Mongo do
@doc """
Getting Collection Names
"""
@spec show_collections(GenServer.server(), Keyword.t()) :: cursor
@spec show_collections(GenServer.server(), Keyword.t()) :: cursor | {:error, Mongo.Error.t()}
def show_collections(topology_pid, opts \\ []) do
##
# from the specs
Expand Down
1 change: 1 addition & 0 deletions lib/mongo/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ defmodule Mongo.Session do
@impl :gen_statem
# Abort all pending transactions if there any and end session itself.
def terminate(_reason, state, %{pid: pid} = data) do
_=
hauleth marked this conversation as resolved.
Show resolved Hide resolved
if state == :in_transaction do
_ = try_run_txn_command(data, :abortTransaction)
end
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule Mongodb.Mixfile do
description: description(),
package: package(),
dialyzer: [
ignore_warnings: ".dialyzer-ignore.exs",
flags: [:underspecs, :unknown, :unmatched_returns],
plt_add_apps: [:logger, :connection, :db_connection, :mix, :elixir, :ssl, :public_key],
plt_add_deps: :transitive
Expand Down