Skip to content

Windows default_launcher probe_on_error probes for a different signature than what is actually called #491

Description

@rlenhardt

See

-> std::is_same<error_code, decltype(init.on_error(launcher, std::declval<const filesystem::path &>(), std::declval<std::wstring &>(), std::declval<std::error_code&>()))>;

probe_on_error checks for a method that takes a std::error and returns a boost::system::error but the calls to on_error will pass a boost::system::error and return void.

Workaround: add a dummy method with the probe signature to satisfy the compile time check, and add another method with the called signature:

#include <boost/process/v2/process.hpp>
namespace bp = boost::process::v2;
namespace bfs = bp::filesystem;
#include <iostream>
struct print_error
{
    template<typename Launcher>
    boost::system::error_code on_error(Launcher& launcher, const bfs::path& executable, std::wstring& cmd_line, std::error_code& ec)
    {
        // will never be called but is needed to make the probe_on_error code compile
        return ec;
    }
    template<typename Launcher>
    void on_error(Launcher& launcher, const bfs::path& executable, std::wstring& cmd_line,
                                       boost::system::error_code const& ec)
    {
        // will actually be called
        std::wcerr << "Could not launch " << executable << std::endl << " cmdline: " << cmd_line << std::endl;
        return;
    }
};

#include <boost/asio/io_context.hpp>
int main()
{
    asio::io_context ctx;
    try {
        bp::process(ctx,"notthere.exe",{},print_error{});
    catch(...) {
        std::cout << "Whoops"<<std::endl;
    }
    return 0;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions