Skip to content

Add explanation string to logic exceptions #278

Description

@R-Goc

I was trying out this library and made some logic bug (still not sure what at the time of writing). But all the information I get is logic error. For example in this code in parser.cpp:

    auto
    prepare() ->
        mutable_buffers_type
    {
        nprepare_ = 0;

        switch(state_)
        {
        default:
        case state::reset:
            // reset must be called first
            detail::throw_logic_error();

        case state::start:
            // start must be called first
            detail::throw_logic_error();

        case state::header:
        {
            BOOST_ASSERT(
                m_.h_.size < cfg_->headers.max_size);
            std::size_t n = fb_.capacity();
            BOOST_ASSERT(n <= cfg_->max_overread());
            n = clamp(n, cfg_->max_prepare);
            mbp_[0] = fb_.prepare(n);
            nprepare_ = n;
            return mutable_buffers_type(&mbp_[0], 1);
        }

        case state::header_done:
            // forgot to call parse()
            detail::throw_logic_error();

In all these cases it would be better to instead of having a comment propagate that information into the exception. That way the error actually makes some sense and is helpful to figuring out what is wrong. This either needs changing detail::throw_logic_error or a new overload.

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