ned14 / outcome

Provides very lightweight outcome<T> and result<T> (non-Boost edition)
https://ned14.github.io/outcome
Other
704 stars 62 forks source link

source_location says nothing! #298

Closed heretic13 closed 3 months ago

heretic13 commented 6 months ago

Hello.

I wrote a test program.

#include <iostream>
#include <boost/outcome/outcome.hpp>
namespace outcome = BOOST_OUTCOME_V2_NAMESPACE;

#include <boost/core/verbose_terminate_handler.hpp>

outcome::result< int > GetParameter()
{
    return boost::system::errc::invalid_argument;
}

void DoTest()
{
    const auto res=GetParameter();

    std::cout<<res.value()<<std::endl;
}

int main()
{
    std::set_terminate(boost::core::verbose_terminate_handler);

    DoTest();
}

When I run the program, it crashes as expected.

But the source_location that is attached to the exception does not say anything - it refers to the file and line number inside the "outcome" library.

If I use boost::system::result then the source_location will refer to the position where there was an unsuccessful .value() call on the result<> object. Because the boost::system::result::value() method creates a source_location object at this very moment.

I know for sure that in Rust, a similar .value() call to "result" in the trace should show the line of code for the unsuccessful .value() call.

I have a question. Is this buggy behavior in the "outcome" library and will it be fixed? Or is this a “feature” of your library?

heretic13 commented 6 months ago

image No useful information about the location of the error

heretic13 commented 6 months ago

Replacing

boost::system::result<int> GetParameter()
{
    return make_error_code(boost::system::errc::invalid_argument);
}

compile and run

image

more usefull information

ned14 commented 6 months ago

Boost system result can hard assume the presence of Boost exceptions, and thus tailor itself so.

There is a sizeable minority of Outcome users who cannot accept the use of source_location, as it bloats binaries and makes them unusable for embedded targets.

For this reason, no default location capture has been implemented, but we did provide hooks via which you can implement your own. Indeed the tutorial https://ned14.github.io/outcome/tutorial/advanced/hooks/keeping_state/ describes a stack backtrace capturing implementation.

Unlike Boost.System, Outcome is ABI stable so extending .value() to capture source_location won't be possible.

ned14 commented 3 months ago

I'm going to assume this issue is closed. Thanks for the feedback.