Jonn Mostovoy
Serokell.io & Doma.dev
- Recoverable (think
Result<E, O>
) - Irrecoverable (think
panic!()
)
- Recoverable (think
Result<E, O>
) - Supervised (think
throw-catch
)
- FT systems: survive the "chaos monkey"
- Correct systems (?): evidence that "chaos monkey" won't happen
- Complexity causes emergence
- You can't precisely / statically analyse it
cat <<EOF | iex -S mix
File.read("flake.nix") |> elem(0)
EOF
- Atoms encode into ints
- Lightest error tagging under distribution
- For most use cases it's a non-issue
- (we wouldn't have been using HTTP then)
{:ok, {:error, "Something went wrong"}}
{:error, "Something went boom"}
{:error, "Something went boom", %{original :data}}
{:error, %{original: :data}}
# Yes, this exists in the wild!
{:ok, %{error:
%{reason: "something went boom",
data: %{original: :data}}
}}
- Exceptions are verbose
- Allow access to stacktrace
cat <<EOF | iex -S mix
File.read!("flake.nixx")
EOF
cat <<EOF | iex -S mix
alias Uptight.Result
:erlang.system_flag(:backtrace_depth, 1)
Result.new(fn -> File.read!("flake.nixx") end)
EOF
cat <<EOF | iex -S mix
use Witchcraft
alias Uptight.Result
import Witchcraft.Comonad
Result.new(fn -> 42 end)
~> (&(&1 + 1))
|> extract() == 43
EOF
cat <<EOF | iex -S mix
use Witchcraft
alias Uptight.Result
import Witchcraft.Comonad
:erlang.system_flag(:backtrace_depth, 1)
Result.new(fn -> 5 = 2 + 2 end)
~> (&(&1 + 1))
~> (&(&1 + 1))
EOF
cat <<EOF | iex -S mix
alias Uptight.Result
import Uptight.Assertions
:erlang.system_flag(:backtrace_depth, 1)
Result.new(fn ->
assert match?(5, 2 + 2), "big brother is watching"
end).err.exception.message
EOF