forked from boostorg/beast
Add file and line number to thrown exceptions
This commit is contained in:
@@ -253,7 +253,8 @@ private:
|
|||||||
reference
|
reference
|
||||||
dereference(C<sizeof...(Bn)> const&) const
|
dereference(C<sizeof...(Bn)> const&) const
|
||||||
{
|
{
|
||||||
throw std::logic_error("invalid iterator");
|
throw detail::make_exception<std::logic_error>(
|
||||||
|
"invalid iterator", __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t I>
|
template<std::size_t I>
|
||||||
@@ -269,7 +270,8 @@ private:
|
|||||||
void
|
void
|
||||||
increment(C<sizeof...(Bn)> const&)
|
increment(C<sizeof...(Bn)> const&)
|
||||||
{
|
{
|
||||||
throw std::logic_error("invalid iterator");
|
throw detail::make_exception<std::logic_error>(
|
||||||
|
"invalid iterator", __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t I>
|
template<std::size_t I>
|
||||||
@@ -310,7 +312,8 @@ private:
|
|||||||
--iter<I>();
|
--iter<I>();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw std::logic_error("invalid iterator");
|
throw detail::make_exception<std::logic_error>(
|
||||||
|
"invalid iterator", __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t I>
|
template<std::size_t I>
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace beast {
|
namespace beast {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
@@ -78,6 +80,18 @@ struct repeat_tuple<0, T>
|
|||||||
using type = std::tuple<>;
|
using type = std::tuple<>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<class Exception>
|
||||||
|
Exception
|
||||||
|
make_exception(char const* reason, char const* file, int line)
|
||||||
|
{
|
||||||
|
char const* n = file;
|
||||||
|
for(auto p = file; *p; ++p)
|
||||||
|
if(*p == '\\' || *p == '/')
|
||||||
|
n = p + 1;
|
||||||
|
return Exception{std::string(reason) + " (" +
|
||||||
|
n + ":" + std::to_string(line) + ")"};
|
||||||
|
}
|
||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
} // beast
|
} // beast
|
||||||
|
|
||||||
|
@@ -524,8 +524,8 @@ basic_streambuf<Allocator>::basic_streambuf(
|
|||||||
, alloc_size_(alloc_size)
|
, alloc_size_(alloc_size)
|
||||||
{
|
{
|
||||||
if(alloc_size <= 0)
|
if(alloc_size <= 0)
|
||||||
throw std::invalid_argument(
|
throw detail::make_exception<std::invalid_argument>(
|
||||||
"basic_streambuf: invalid alloc_size");
|
"invalid alloc_size", __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Allocator>
|
template<class Allocator>
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#ifndef BEAST_IMPL_BUFFERS_ADAPTER_IPP
|
#ifndef BEAST_IMPL_BUFFERS_ADAPTER_IPP
|
||||||
#define BEAST_IMPL_BUFFERS_ADAPTER_IPP
|
#define BEAST_IMPL_BUFFERS_ADAPTER_IPP
|
||||||
|
|
||||||
|
#include <beast/core/detail/type_traits.hpp>
|
||||||
#include <boost/asio/buffer.hpp>
|
#include <boost/asio/buffer.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -413,8 +414,8 @@ buffers_adapter<MutableBufferSequence>::prepare(std::size_t n) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(n > 0)
|
if(n > 0)
|
||||||
throw std::length_error(
|
throw detail::make_exception<std::length_error>(
|
||||||
"no space in buffers_adapter");
|
"no space", __FILE__, __LINE__);
|
||||||
return mutable_buffers_type{*this};
|
return mutable_buffers_type{*this};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#ifndef BEAST_IMPL_STATIC_STREAMBUF_IPP
|
#ifndef BEAST_IMPL_STATIC_STREAMBUF_IPP
|
||||||
#define BEAST_IMPL_STATIC_STREAMBUF_IPP
|
#define BEAST_IMPL_STATIC_STREAMBUF_IPP
|
||||||
|
|
||||||
|
#include <beast/core/detail/type_traits.hpp>
|
||||||
#include <boost/asio/buffer.hpp>
|
#include <boost/asio/buffer.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -295,7 +296,8 @@ static_streambuf::prepare(std::size_t n) ->
|
|||||||
mutable_buffers_type
|
mutable_buffers_type
|
||||||
{
|
{
|
||||||
if(n > static_cast<std::size_t>(end_ - out_))
|
if(n > static_cast<std::size_t>(end_ - out_))
|
||||||
throw std::length_error("no space in streambuf");
|
throw detail::make_exception<std::length_error>(
|
||||||
|
"no space in streambuf", __FILE__, __LINE__);
|
||||||
last_ = out_ + n;
|
last_ = out_ + n;
|
||||||
return mutable_buffers_type{out_, n};
|
return mutable_buffers_type{out_, n};
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#ifndef BEAST_WEBSOCKET_STATIC_STRING_HPP
|
#ifndef BEAST_WEBSOCKET_STATIC_STRING_HPP
|
||||||
#define BEAST_WEBSOCKET_STATIC_STRING_HPP
|
#define BEAST_WEBSOCKET_STATIC_STRING_HPP
|
||||||
|
|
||||||
|
#include <beast/core/detail/type_traits.hpp>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
@@ -329,7 +330,8 @@ static_string<N, CharT, Traits>::
|
|||||||
static_string(static_string<M, CharT, Traits> const& s)
|
static_string(static_string<M, CharT, Traits> const& s)
|
||||||
{
|
{
|
||||||
if(s.size() > N)
|
if(s.size() > N)
|
||||||
throw std::length_error("static_string overflow");
|
throw detail::make_exception<std::length_error>(
|
||||||
|
"static_string overflow", __FILE__, __LINE__);
|
||||||
n_ = s.size();
|
n_ = s.size();
|
||||||
Traits::copy(&s_[0], &s.s_[0], n_ + 1);
|
Traits::copy(&s_[0], &s.s_[0], n_ + 1);
|
||||||
}
|
}
|
||||||
@@ -353,7 +355,8 @@ operator=(static_string<M, CharT, Traits> const& s) ->
|
|||||||
static_string&
|
static_string&
|
||||||
{
|
{
|
||||||
if(s.size() > N)
|
if(s.size() > N)
|
||||||
throw std::length_error("static_string overflow");
|
throw detail::make_exception<std::length_error>(
|
||||||
|
"static_string overflow", __FILE__, __LINE__);
|
||||||
n_ = s.size();
|
n_ = s.size();
|
||||||
Traits::copy(&s_[0], &s.s_[0], n_ + 1);
|
Traits::copy(&s_[0], &s.s_[0], n_ + 1);
|
||||||
return *this;
|
return *this;
|
||||||
@@ -391,7 +394,8 @@ at(size_type pos) ->
|
|||||||
reference
|
reference
|
||||||
{
|
{
|
||||||
if(pos >= n_)
|
if(pos >= n_)
|
||||||
throw std::out_of_range("static_string::at");
|
throw detail::make_exception<std::out_of_range>(
|
||||||
|
"invalid pos", __FILE__, __LINE__);
|
||||||
return s_[pos];
|
return s_[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +406,8 @@ at(size_type pos) const ->
|
|||||||
const_reference
|
const_reference
|
||||||
{
|
{
|
||||||
if(pos >= n_)
|
if(pos >= n_)
|
||||||
throw std::out_of_range("static_string::at");
|
throw detail::make_exception<std::out_of_range>(
|
||||||
|
"static_string::at", __FILE__, __LINE__);
|
||||||
return s_[pos];
|
return s_[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,7 +417,8 @@ static_string<N, CharT, Traits>::
|
|||||||
resize(std::size_t n)
|
resize(std::size_t n)
|
||||||
{
|
{
|
||||||
if(n > N)
|
if(n > N)
|
||||||
throw std::length_error("static_string overflow");
|
throw detail::make_exception<std::length_error>(
|
||||||
|
"static_string overflow", __FILE__, __LINE__);
|
||||||
n_ = n;
|
n_ = n;
|
||||||
s_[n_] = 0;
|
s_[n_] = 0;
|
||||||
}
|
}
|
||||||
@@ -423,7 +429,8 @@ static_string<N, CharT, Traits>::
|
|||||||
resize(std::size_t n, CharT c)
|
resize(std::size_t n, CharT c)
|
||||||
{
|
{
|
||||||
if(n > N)
|
if(n > N)
|
||||||
throw std::length_error("static_string overflow");
|
throw detail::make_exception<std::length_error>(
|
||||||
|
"static_string overflow", __FILE__, __LINE__);
|
||||||
if(n > n_)
|
if(n > n_)
|
||||||
Traits::assign(&s_[n_], n - n_, c);
|
Traits::assign(&s_[n_], n - n_, c);
|
||||||
n_ = n;
|
n_ = n;
|
||||||
@@ -462,7 +469,8 @@ assign(CharT const* s)
|
|||||||
{
|
{
|
||||||
auto const n = Traits::length(s);
|
auto const n = Traits::length(s);
|
||||||
if(n > N)
|
if(n > N)
|
||||||
throw std::out_of_range("too large");
|
throw detail::make_exception<std::out_of_range>(
|
||||||
|
"too large", __FILE__, __LINE__);
|
||||||
n_ = n;
|
n_ = n;
|
||||||
Traits::copy(&s_[0], s, n_ + 1);
|
Traits::copy(&s_[0], s, n_ + 1);
|
||||||
}
|
}
|
||||||
|
@@ -159,6 +159,8 @@ void
|
|||||||
prepare(message<isRequest, Body, Fields>& msg,
|
prepare(message<isRequest, Body, Fields>& msg,
|
||||||
Options&&... options)
|
Options&&... options)
|
||||||
{
|
{
|
||||||
|
using beast::detail::make_exception;
|
||||||
|
|
||||||
// VFALCO TODO
|
// VFALCO TODO
|
||||||
static_assert(is_Body<Body>::value,
|
static_assert(is_Body<Body>::value,
|
||||||
"Body requirements not met");
|
"Body requirements not met");
|
||||||
@@ -174,16 +176,16 @@ prepare(message<isRequest, Body, Fields>& msg,
|
|||||||
std::forward<Options>(options)...);
|
std::forward<Options>(options)...);
|
||||||
|
|
||||||
if(msg.fields.exists("Connection"))
|
if(msg.fields.exists("Connection"))
|
||||||
throw std::invalid_argument(
|
throw make_exception<std::invalid_argument>(
|
||||||
"prepare called with Connection field set");
|
"prepare called with Connection field set", __FILE__, __LINE__);
|
||||||
|
|
||||||
if(msg.fields.exists("Content-Length"))
|
if(msg.fields.exists("Content-Length"))
|
||||||
throw std::invalid_argument(
|
throw make_exception<std::invalid_argument>(
|
||||||
"prepare called with Content-Length field set");
|
"prepare called with Content-Length field set", __FILE__, __LINE__);
|
||||||
|
|
||||||
if(token_list{msg.fields["Transfer-Encoding"]}.exists("chunked"))
|
if(token_list{msg.fields["Transfer-Encoding"]}.exists("chunked"))
|
||||||
throw std::invalid_argument(
|
throw make_exception<std::invalid_argument>(
|
||||||
"prepare called with Transfer-Encoding: chunked set");
|
"prepare called with Transfer-Encoding: chunked set", __FILE__, __LINE__);
|
||||||
|
|
||||||
if(pi.connection_value != connection::upgrade)
|
if(pi.connection_value != connection::upgrade)
|
||||||
{
|
{
|
||||||
@@ -254,8 +256,8 @@ prepare(message<isRequest, Body, Fields>& msg,
|
|||||||
// rfc7230 6.7.
|
// rfc7230 6.7.
|
||||||
if(msg.version < 11 && token_list{
|
if(msg.version < 11 && token_list{
|
||||||
msg.fields["Connection"]}.exists("upgrade"))
|
msg.fields["Connection"]}.exists("upgrade"))
|
||||||
throw std::invalid_argument(
|
throw make_exception<std::invalid_argument>(
|
||||||
"invalid version for Connection: upgrade");
|
"invalid version for Connection: upgrade", __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // http
|
} // http
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include <beast/core/prepare_buffers.hpp>
|
#include <beast/core/prepare_buffers.hpp>
|
||||||
#include <beast/core/static_streambuf.hpp>
|
#include <beast/core/static_streambuf.hpp>
|
||||||
#include <beast/core/stream_concepts.hpp>
|
#include <beast/core/stream_concepts.hpp>
|
||||||
|
#include <beast/core/detail/type_traits.hpp>
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/endian/buffers.hpp>
|
#include <boost/endian/buffers.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <beast/websocket/rfc6455.hpp>
|
#include <beast/websocket/rfc6455.hpp>
|
||||||
#include <beast/websocket/detail/decorator.hpp>
|
#include <beast/websocket/detail/decorator.hpp>
|
||||||
|
#include <beast/core/detail/type_traits.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -186,7 +187,8 @@ struct message_type
|
|||||||
message_type(opcode op)
|
message_type(opcode op)
|
||||||
{
|
{
|
||||||
if(op != opcode::binary && op != opcode::text)
|
if(op != opcode::binary && op != opcode::text)
|
||||||
throw std::domain_error("bad opcode");
|
throw beast::detail::make_exception<std::invalid_argument>(
|
||||||
|
"bad opcode", __FILE__, __LINE__);
|
||||||
value = op;
|
value = op;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -277,6 +279,9 @@ struct read_buffer_size
|
|||||||
read_buffer_size(std::size_t n)
|
read_buffer_size(std::size_t n)
|
||||||
: value(n)
|
: value(n)
|
||||||
{
|
{
|
||||||
|
if(n < 8)
|
||||||
|
throw beast::detail::make_exception<std::invalid_argument>(
|
||||||
|
"read buffer size is too small", __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -356,7 +361,8 @@ struct write_buffer_size
|
|||||||
: value(n)
|
: value(n)
|
||||||
{
|
{
|
||||||
if(n < 8)
|
if(n < 8)
|
||||||
throw std::domain_error("write buffer size is too small");
|
throw beast::detail::make_exception<std::invalid_argument>(
|
||||||
|
"write buffer size is too small", __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include <beast/zlib/zlib.hpp>
|
#include <beast/zlib/zlib.hpp>
|
||||||
#include <beast/zlib/detail/ranges.hpp>
|
#include <beast/zlib/detail/ranges.hpp>
|
||||||
|
#include <beast/core/detail/type_traits.hpp>
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -893,14 +894,19 @@ doReset(
|
|||||||
if(windowBits == 8)
|
if(windowBits == 8)
|
||||||
windowBits = 9;
|
windowBits = 9;
|
||||||
|
|
||||||
|
using beast::detail::make_exception;
|
||||||
|
|
||||||
if(level < 0 || level > 9)
|
if(level < 0 || level > 9)
|
||||||
throw std::invalid_argument{"invalid level"};
|
throw make_exception<std::invalid_argument>(
|
||||||
|
"invalid level", __FILE__, __LINE__);
|
||||||
|
|
||||||
if(windowBits < 8 || windowBits > 15)
|
if(windowBits < 8 || windowBits > 15)
|
||||||
throw std::invalid_argument{"invalid windowBits"};
|
throw make_exception<std::invalid_argument>(
|
||||||
|
"invalid windowBits", __FILE__, __LINE__);
|
||||||
|
|
||||||
if(memLevel < 1 || memLevel > MAX_MEM_LEVEL)
|
if(memLevel < 1 || memLevel > MAX_MEM_LEVEL)
|
||||||
throw std::invalid_argument{"invalid memLevel"};
|
throw make_exception<std::invalid_argument>(
|
||||||
|
"invalid memLevel", __FILE__, __LINE__);
|
||||||
|
|
||||||
w_bits_ = windowBits;
|
w_bits_ = windowBits;
|
||||||
|
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
#include <beast/zlib/detail/bitstream.hpp>
|
#include <beast/zlib/detail/bitstream.hpp>
|
||||||
#include <beast/zlib/detail/ranges.hpp>
|
#include <beast/zlib/detail/ranges.hpp>
|
||||||
#include <beast/zlib/detail/window.hpp>
|
#include <beast/zlib/detail/window.hpp>
|
||||||
|
#include <beast/core/detail/type_traits.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -232,7 +233,8 @@ inflate_stream::
|
|||||||
doReset(int windowBits)
|
doReset(int windowBits)
|
||||||
{
|
{
|
||||||
if(windowBits < 8 || windowBits > 15)
|
if(windowBits < 8 || windowBits > 15)
|
||||||
throw std::domain_error("windowBits out of range");
|
throw beast::detail::make_exception<std::domain_error>(
|
||||||
|
"windowBits out of range", __FILE__, __LINE__);
|
||||||
w_.reset(windowBits);
|
w_.reset(windowBits);
|
||||||
|
|
||||||
bi_.flush();
|
bi_.flush();
|
||||||
@@ -706,7 +708,8 @@ doWrite(z_params& zs, Flush flush, error_code& ec)
|
|||||||
|
|
||||||
case SYNC:
|
case SYNC:
|
||||||
default:
|
default:
|
||||||
throw std::logic_error("stream error");
|
throw beast::detail::make_exception<std::logic_error>(
|
||||||
|
"stream error", __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -932,8 +935,8 @@ inflate_table(
|
|||||||
|
|
||||||
auto const not_enough = []
|
auto const not_enough = []
|
||||||
{
|
{
|
||||||
throw std::logic_error(
|
throw beast::detail::make_exception<std::logic_error>(
|
||||||
"insufficient output size when inflating tables");
|
"insufficient output size when inflating tables", __FILE__, __LINE__);
|
||||||
};
|
};
|
||||||
|
|
||||||
// check available table space
|
// check available table space
|
||||||
|
@@ -160,8 +160,8 @@ private:
|
|||||||
auto& d = *d_;
|
auto& d = *d_;
|
||||||
d.ws.set_option(decorate(identity{}));
|
d.ws.set_option(decorate(identity{}));
|
||||||
d.ws.set_option(read_message_max(64 * 1024 * 1024));
|
d.ws.set_option(read_message_max(64 * 1024 * 1024));
|
||||||
d.ws.set_option(auto_fragment{false});
|
//d.ws.set_option(auto_fragment{false});
|
||||||
d.ws.set_option(write_buffer_size{64 * 1024});
|
//d.ws.set_option(write_buffer_size{64 * 1024});
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user