SnakeBridge.SerializationError exception (SnakeBridge v0.7.4)

View Source

Raised when attempting to encode a value that cannot be serialized for Python.

SnakeBridge supports encoding:

  • Primitives: nil, booleans, integers, floats, strings
  • Collections: lists, maps, tuples, MapSets
  • Special types: atoms, DateTime, Date, Time, SnakeBridge.Bytes
  • References: SnakeBridge.Ref, SnakeBridge.StreamRef
  • Functions: anonymous functions (as callbacks)
  • Special floats: :infinity, :neg_infinity, :nan

Types that cannot be serialized:

  • PIDs, ports, references
  • Custom structs without serialization support
  • File handles, sockets, other system resources

Resolution

For unsupported types, you have several options:

  1. Create a Python object and pass the ref:

    {:ok, ref} = SnakeBridge.call("module", "create_object", [...])
    SnakeBridge.call("module", "use_object", [ref])
  2. Convert to a supported type:

    # Instead of passing a PID
    SnakeBridge.call("module", "fn", [inspect(pid)])
    # Or extract relevant data
    SnakeBridge.call("module", "fn", [pid_to_list(pid)])
  3. Use explicit bytes for binary data:

    SnakeBridge.call("module", "fn", [SnakeBridge.bytes(binary)])

Summary

Functions

Creates a SerializationError from a message string.

Types

t()

@type t() :: %SnakeBridge.SerializationError{
  __exception__: true,
  message: String.t(),
  type: atom() | module(),
  value: term()
}

Functions

new(message \\ nil)

@spec new(String.t() | nil) :: t()

Creates a SerializationError from a message string.

This is used for error messages from the Python side.