Linx.Cgroup.Error exception (Linx v0.1.0)

Copy Markdown View Source

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 raised or rendered with Exception.message/1.

Summary

Functions

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

Types

operation()

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

t()

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

Functions

from_posix(errno, path, operation)

@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.