-module(thrifty@fuzz_persistence). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/thrifty/fuzz_persistence.gleam"). -export([persist_failure/5]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/thrifty/fuzz_persistence.gleam", 36). ?DOC( " Persist a failing fuzz payload and associated metadata.\n" "\n" " Inputs\n" " - `dir`: output directory. Created if it does not already exist.\n" " - `seed`: deterministic seed used when generating the payload.\n" " - `iter`: iteration index within the seed loop.\n" " - `data`: the mutated payload bytes to persist.\n" " - `reason`: the decode error that triggered persistence.\n" "\n" " Outputs\n" " - `Ok(Nil)` when both payload and metadata are written successfully.\n" " - `Error(String)` when directory creation or file writes fail.\n" "\n" " The metadata is stored as a text file containing simple `key=value` lines\n" " for quick inspection.\n" ). -spec persist_failure( binary(), integer(), integer(), bitstring(), thrifty@types:decode_error() ) -> {ok, nil} | {error, binary()}. persist_failure(Dir, Seed, Iter, Data, Reason) -> case thrifty@file_io:ensure_dir(Dir) of {error, E} -> {error, E}; {ok, _} -> Basename = <<<<<<"fuzz-failure-"/utf8, (erlang:integer_to_binary(Seed))/binary>>/binary, "-"/utf8>>/binary, (erlang:integer_to_binary(Iter))/binary>>, Bin_path = <<<<<