# `Linx.Cgroup.Error`
[🔗](https://github.com/oshlabs/linx/blob/v0.2.0/lib/linx/cgroup/error.ex#L1)

An error returned by a `Linx.Cgroup` operation.

Built from a failed `File.read/1` / `File.write/2` / `File.mkdir/1` /
`File.rmdir/1` call against a cgroupfs interface file. The shape:

  * `:path` — the absolute filesystem path the operation targeted.
  * `:operation` — what we were trying to do, as an atom
    (`:create`, `:destroy`, `:read`, `:write`, `:add_process`).
  * `:errno` — the POSIX errno as an atom (`:enoent`, `:eacces`,
    `:ebusy`, …). File already hands us atoms; we keep them as
    named.
  * `:code` — the matching positive errno integer, or `nil` if we
    don't have a mapping for this atom. Included for symmetry with
    `Linx.Netlink.Error` and for callers unfamiliar with POSIX
    mnemonics.

Pattern-match on `:errno` and `:operation` to handle specific
failures:

    case Linx.Cgroup.destroy(cg) do
      :ok -> :ok
      {:error, %Linx.Cgroup.Error{errno: :ebusy}} ->
        # cgroup still has processes -- expected for live workloads
        :not_empty
    end

Implements `Exception`, so an error can be `raise`d or rendered
with `Exception.message/1`.

# `operation`

```elixir
@type operation() :: :create | :destroy | :read | :write | :add_process | :stats
```

# `t`

```elixir
@type t() :: %Linx.Cgroup.Error{
  __exception__: true,
  code: pos_integer() | nil,
  errno: atom(),
  operation: operation(),
  path: Path.t()
}
```

# `from_posix`

```elixir
@spec from_posix(atom(), Path.t(), operation()) :: t()
```

Builds a `%Linx.Cgroup.Error{}` from a posix-atom errno, the
filesystem path that failed, and the operation we attempted.

The integer `:code` is looked up from a small POSIX table; an
atom we don't have a mapping for (kernel-specific errno on
exotic hosts) keeps `:code` at `nil`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
