SnmpKit.SnmpMgr.Errors (snmpkit v0.6.3)

SNMP error handling and error code translation.

Provides functions to handle both SNMPv1 and SNMPv2c error conditions and translate error codes to human-readable messages.

Summary

Functions

Enhanced error analysis using SnmpKit.SnmpLib.Error for SNMP protocol errors.

Classifies an error into a category for better handling.

Translates an SNMP error code to an atom.

Translates an error code directly to a description.

Translates an SNMP error atom to a human-readable description.

Formats an SNMP error for display.

Formats an error message in a user-friendly way with context.

Provides recovery suggestions for common errors.

Determines if an error is version-specific.

Checks if an error is recoverable (can be retried).

Functions

analyze_error(error)

Enhanced error analysis using SnmpKit.SnmpLib.Error for SNMP protocol errors.

Provides detailed error information including severity and RFC compliance for SNMP protocol errors while preserving our comprehensive network error handling.

Examples

iex> SnmpKit.SnmpMgr.Errors.analyze_error({:snmp_error, 2})
%{
  type: :snmp_protocol,
  atom: :no_such_name,
  code: 2,
  severity: :error,
  retriable: false,
  category: :user_error,
  description: "Variable name not found"
}

iex> SnmpKit.SnmpMgr.Errors.analyze_error(:timeout)
%{
  type: :network,
  atom: :timeout,
  retriable: true,
  category: :transient_error,
  description: "Operation timed out"
}

classify_error(error, context \\ nil)

Classifies an error into a category for better handling.

Examples

iex> SnmpKit.SnmpMgr.Errors.classify_error({:snmp_error, :no_such_name}, "Get request")
{:user_error, :invalid_oid}

iex> SnmpKit.SnmpMgr.Errors.classify_error({:network_error, :timeout}, "Network operation")
{:transient_error, :network_timeout}

iex> SnmpKit.SnmpMgr.Errors.classify_error({:snmp_error, :too_big}, "Bulk request")
{:recoverable_error, :response_too_large}

code_to_atom(error_code)

Translates an SNMP error code to an atom.

Uses SnmpKit.SnmpLib.Error for validation and standardization of RFC-compliant error codes.

Examples

iex> SnmpKit.SnmpMgr.Errors.code_to_atom(2)
:no_such_name

iex> SnmpKit.SnmpMgr.Errors.code_to_atom(0)
:no_error

iex> SnmpKit.SnmpMgr.Errors.code_to_atom(999)
:unknown_error

code_to_description(error_code)

Translates an error code directly to a description.

Examples

iex> SnmpKit.SnmpMgr.Errors.code_to_description(2)
"Variable name not found"

iex> SnmpKit.SnmpMgr.Errors.code_to_description(18)
"Inconsistent name"

description(error_atom)

Translates an SNMP error atom to a human-readable description.

Examples

iex> SnmpKit.SnmpMgr.Errors.description(:no_such_name)
"Variable name not found"

iex> SnmpKit.SnmpMgr.Errors.description(:too_big)
"Response too big to fit in message"

iex> SnmpKit.SnmpMgr.Errors.description(:unknown_error)
"Unknown error"

format_error(error)

Formats an SNMP error for display.

Examples

iex> SnmpKit.SnmpMgr.Errors.format_error({:snmp_error, 2})
"SNMP Error (2): Variable name not found"

iex> SnmpKit.SnmpMgr.Errors.format_error({:snmp_error, :no_such_name})
"SNMP Error: Variable name not found"

iex> SnmpKit.SnmpMgr.Errors.format_error({:v2c_error, :no_access, oid: "1.2.3.4"})
"SNMPv2c Error: Access denied (OID: 1.2.3.4)"

format_user_friendly_error(error, context \\ "Operation")

Formats an error message in a user-friendly way with context.

Examples

iex> SnmpKit.SnmpMgr.Errors.format_user_friendly_error({:snmp_error, :no_such_name}, "Getting system description")
"Unable to get system description: The requested OID does not exist on the device"

iex> SnmpKit.SnmpMgr.Errors.format_user_friendly_error({:network_error, :timeout}, "Contacting device")
"Failed contacting device: The device did not respond within the timeout period"

get_recovery_suggestions(arg1)

Provides recovery suggestions for common errors.

Examples

iex> SnmpKit.SnmpMgr.Errors.get_recovery_suggestions({:snmp_error, :no_such_name})
["Verify the OID is correct", "Check if the OID is supported by this device", "Try using MIB browser to explore available OIDs"]

iex> SnmpKit.SnmpMgr.Errors.get_recovery_suggestions({:network_error, :timeout})
["Increase timeout value", "Check network connectivity", "Verify device is responding to ping"]

is_v2c_error?(error_atom)

Determines if an error is version-specific.

Examples

iex> SnmpKit.SnmpMgr.Errors.is_v2c_error?(:no_access)
true

iex> SnmpKit.SnmpMgr.Errors.is_v2c_error?(:no_such_name)
false

recoverable?(arg1)

Checks if an error is recoverable (can be retried).

Examples

iex> SnmpKit.SnmpMgr.Errors.recoverable?({:network_error, :host_unreachable})
false

iex> SnmpKit.SnmpMgr.Errors.recoverable?({:snmp_error, :too_big})
true

iex> SnmpKit.SnmpMgr.Errors.recoverable?(:timeout)
true