|
1 | 1 | defmodule Codex.Plugins.Errors do |
2 | 2 | @moduledoc false |
3 | 3 |
|
4 | | - @spec io(atom(), Path.t(), term()) :: {:plugin_io, map()} |
5 | | - def io(action, path, reason) when is_atom(action) do |
| 4 | + @type io_error :: {:plugin_io, %{action: atom(), path: String.t(), reason: term()}} |
| 5 | + @type invalid_json_error :: |
| 6 | + {:invalid_plugin_json, %{path: String.t(), reason: String.t(), raw_reason: term()}} |
| 7 | + @type file_exists_error :: {:plugin_file_exists, %{path: String.t()}} |
| 8 | + @type repo_root_not_found_error :: {:repo_root_not_found, %{cwd: String.t()}} |
| 9 | + @type invalid_scope_error :: {:invalid_plugin_scope, %{scope: term()}} |
| 10 | + @type invalid_plugin_name_error :: |
| 11 | + {:invalid_plugin_name, %{name: term(), message: String.t()}} |
| 12 | + @type invalid_plugin_root_error :: |
| 13 | + {:invalid_plugin_root, %{path: String.t(), message: String.t()}} |
| 14 | + @type invalid_marketplace_path_error :: |
| 15 | + {:invalid_marketplace_path, %{path: String.t(), message: String.t()}} |
| 16 | + @type invalid_marketplace_source_path_error :: |
| 17 | + {:invalid_marketplace_source_path, |
| 18 | + %{path: String.t(), source_path: String.t(), message: String.t()}} |
| 19 | + @type plugin_conflict_error :: |
| 20 | + {:plugin_conflict, %{path: String.t(), plugin_name: String.t()}} |
| 21 | + |
| 22 | + @type t :: |
| 23 | + io_error() |
| 24 | + | invalid_json_error() |
| 25 | + | file_exists_error() |
| 26 | + | repo_root_not_found_error() |
| 27 | + | invalid_scope_error() |
| 28 | + | invalid_plugin_name_error() |
| 29 | + | invalid_plugin_root_error() |
| 30 | + | invalid_marketplace_path_error() |
| 31 | + | invalid_marketplace_source_path_error() |
| 32 | + | plugin_conflict_error() |
| 33 | + |
| 34 | + @spec io(atom(), String.t(), term()) :: io_error() |
| 35 | + def io(action, path, reason) when is_atom(action) and is_binary(path) do |
6 | 36 | {:plugin_io, %{action: action, path: Path.expand(path), reason: reason}} |
7 | 37 | end |
8 | 38 |
|
9 | | - @spec invalid_json(Path.t(), term()) :: {:invalid_plugin_json, map()} |
10 | | - def invalid_json(path, reason) do |
| 39 | + @spec invalid_json(String.t(), term()) :: invalid_json_error() |
| 40 | + def invalid_json(path, reason) when is_binary(path) do |
11 | 41 | {:invalid_plugin_json, |
12 | 42 | %{path: Path.expand(path), reason: format_reason(reason), raw_reason: reason}} |
13 | 43 | end |
14 | 44 |
|
15 | | - @spec file_exists(Path.t()) :: {:plugin_file_exists, map()} |
16 | | - def file_exists(path), do: {:plugin_file_exists, %{path: Path.expand(path)}} |
| 45 | + @spec file_exists(String.t()) :: file_exists_error() |
| 46 | + def file_exists(path) when is_binary(path), |
| 47 | + do: {:plugin_file_exists, %{path: Path.expand(path)}} |
17 | 48 |
|
18 | | - @spec repo_root_not_found(Path.t()) :: {:repo_root_not_found, map()} |
19 | | - def repo_root_not_found(path), do: {:repo_root_not_found, %{cwd: Path.expand(path)}} |
| 49 | + @spec repo_root_not_found(String.t()) :: repo_root_not_found_error() |
| 50 | + def repo_root_not_found(path) when is_binary(path), |
| 51 | + do: {:repo_root_not_found, %{cwd: Path.expand(path)}} |
20 | 52 |
|
21 | | - @spec invalid_scope(term()) :: {:invalid_plugin_scope, map()} |
| 53 | + @spec invalid_scope(term()) :: invalid_scope_error() |
22 | 54 | def invalid_scope(scope), do: {:invalid_plugin_scope, %{scope: scope}} |
23 | 55 |
|
24 | | - @spec invalid_plugin_name(term(), String.t()) :: {:invalid_plugin_name, map()} |
| 56 | + @spec invalid_plugin_name(term(), String.t()) :: invalid_plugin_name_error() |
25 | 57 | def invalid_plugin_name(name, message), |
26 | 58 | do: {:invalid_plugin_name, %{name: name, message: message}} |
27 | 59 |
|
28 | | - @spec invalid_plugin_root(Path.t(), String.t()) :: {:invalid_plugin_root, map()} |
29 | | - def invalid_plugin_root(path, message), |
| 60 | + @spec invalid_plugin_root(String.t(), String.t()) :: invalid_plugin_root_error() |
| 61 | + def invalid_plugin_root(path, message) when is_binary(path), |
30 | 62 | do: {:invalid_plugin_root, %{path: Path.expand(path), message: message}} |
31 | 63 |
|
32 | | - @spec invalid_marketplace_path(Path.t(), String.t()) :: {:invalid_marketplace_path, map()} |
33 | | - def invalid_marketplace_path(path, message), |
| 64 | + @spec invalid_marketplace_path(String.t(), String.t()) :: invalid_marketplace_path_error() |
| 65 | + def invalid_marketplace_path(path, message) when is_binary(path), |
34 | 66 | do: {:invalid_marketplace_path, %{path: Path.expand(path), message: message}} |
35 | 67 |
|
36 | | - @spec invalid_marketplace_source_path(Path.t(), String.t(), String.t()) :: |
37 | | - {:invalid_marketplace_source_path, map()} |
38 | | - def invalid_marketplace_source_path(path, source_path, message) do |
| 68 | + @spec invalid_marketplace_source_path(String.t(), String.t(), String.t()) :: |
| 69 | + invalid_marketplace_source_path_error() |
| 70 | + def invalid_marketplace_source_path(path, source_path, message) |
| 71 | + when is_binary(path) and is_binary(source_path) do |
39 | 72 | {:invalid_marketplace_source_path, |
40 | 73 | %{path: Path.expand(path), source_path: source_path, message: message}} |
41 | 74 | end |
42 | 75 |
|
43 | | - @spec plugin_conflict(Path.t(), String.t()) :: {:plugin_conflict, map()} |
44 | | - def plugin_conflict(path, plugin_name) do |
| 76 | + @spec plugin_conflict(String.t(), String.t()) :: plugin_conflict_error() |
| 77 | + def plugin_conflict(path, plugin_name) when is_binary(path) and is_binary(plugin_name) do |
45 | 78 | {:plugin_conflict, %{path: Path.expand(path), plugin_name: plugin_name}} |
46 | 79 | end |
47 | 80 |
|
|
0 commit comments