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

Copy Markdown View Source

An error returned by the kernel in response to a netlink request.

Built from an NLMSG_ERROR reply: code is the kernel's positive errno, errno is its POSIX name as an atom (:enodev, :einval, …), and message is the human-readable string the kernel attached via extended ack (NLMSGERR_ATTR_MSG) — nil if the kernel did not provide one. Extended ack is enabled per socket by Linx.Netlink.Socket.open/2 (Linux ≥ 4.12).

Returned in the error tuple by every netlink verb, e.g.

{:error, %Linx.Netlink.Error{errno: :enodev}} = Link.get(socket, "nope0")

No :operation field

Unlike the filesystem/procfs-backed error structs (Linx.Cgroup.Error, Linx.Mount.Error, …), this struct carries no :operation. A netlink error returns straight from the verb the caller invoked, so the operation is already known at the call site — and the kernel's extended-ack message is a richer, self-describing diagnostic than a synthetic operation tag would be. from_errno/2 is named for what it takes — a numeric wire errno, not a POSIX atom — which is why it differs from the from_posix/_ constructors elsewhere in Linx.

This module also implements Exception so an error can be raised, or rendered with Exception.message/1.

Summary

Functions

Builds an error from a positive errno code and an optional kernel-supplied message (the NLMSGERR_ATTR_MSG string).

Types

t()

@type t() :: %Linx.Netlink.Error{
  __exception__: true,
  code: pos_integer(),
  errno: atom(),
  message: binary() | nil
}

Functions

from_errno(code, message \\ nil)

@spec from_errno(pos_integer(), binary() | nil) :: t()

Builds an error from a positive errno code and an optional kernel-supplied message (the NLMSGERR_ATTR_MSG string).