BareGit
#pragma once

#include <spdlog/spdlog.h>

namespace agent_smith::internal
{

/// Invoke a best-effort observer without allowing exceptions to escape.
template <typename F, typename T> void invokeHook(const F& hook, const T& value)
{
    if(!hook)
    {
        return;
    }
    try
    {
        hook(value);
    }
    catch(...)
    {
        // Do not log exception text: observers may include secrets in it.
        try
        {
            if(auto logger = spdlog::get("agent_smith"))
            {
                logger->warn("agent observer threw; continuing execution");
            }
        }
        catch(...) {}
    }
}

} // namespace agent_smith::internal