Merge branch 'master' of github.com:KLayout/klayout into byte-arrays

This commit is contained in:
Matthias Koefferlein 2021-01-25 08:11:53 +01:00
commit 702852a8a9
4 changed files with 32 additions and 39 deletions

View File

@ -55,7 +55,7 @@ ColdProxy::ColdProxy (db::cell_index_type ci, db::Layout &layout, const ProxyCon
if (! info.lib_name.empty ()) {
tl::MutexLocker locker (&s_map_mutex);
std::map<std::string, tl::weak_collection<ColdProxy> *>::iterator i = s_proxies_per_library_name.find (info.lib_name);
if (i != s_proxies_per_library_name.end ()) {
if (i == s_proxies_per_library_name.end ()) {
i = s_proxies_per_library_name.insert (std::make_pair (info.lib_name, new tl::weak_collection<ColdProxy> ())).first;
}
i->second->push_back (this);

View File

@ -26,6 +26,30 @@
namespace tl
{
// .. nothing yet ..
// ---------------------------------------------------------------
// HttpErrorException implementation
std::string
HttpErrorException::format_error (const std::string &em, int ec, const std::string &url, const std::string &body)
{
std::string msg = tl::sprintf (tl::to_string (tr ("Error %d: %s, fetching %s")), ec, em, url);
if (! body.empty ()) {
msg += "\n\n";
msg += tl::to_string (tr ("Reply body:"));
msg += "\n";
if (body.size () > 1000) {
msg += std::string (body.c_str (), 1000);
msg += "...";
} else {
msg += body;
}
}
return msg;
}
}

View File

@ -56,11 +56,11 @@ class TL_PUBLIC HttpErrorException
: public tl::Exception
{
public:
HttpErrorException (const std::string &f, int ec, QNetworkReply *reply)
: tl::Exception (format_error (f, ec, reply))
HttpErrorException (const std::string &f, int ec, const std::string &url, const std::string &body = std::string ())
: tl::Exception (format_error (f, ec, url, body))
{ }
static std::string format_error (const std::string &em, int ec, QNetworkReply *reply);
static std::string format_error (const std::string &em, int ec, const std::string &url, const std::string &body);
};
class InputHttpStreamPrivateData;

View File

@ -123,39 +123,6 @@ AuthenticationHandler::proxyAuthenticationRequired (const QNetworkProxy &proxy,
// ---------------------------------------------------------------
// InputHttpStream implementation
std::string
HttpErrorException::format_error (const std::string &em, int ec, QNetworkReply *reply)
{
std::string msg = tl::sprintf (tl::to_string (tr ("Error %d: %s, fetching %s")), ec, em, tl::to_string (reply->url ().toString ()));
std::string data = tl::to_string (QString::fromUtf8 (reply->readAll ()));
if (data.size () > 1000) {
data = data.substr (0, size_t (1000)) + "...";
}
if (! data.empty ()) {
msg += "\n\n";
msg += tl::to_string (tr ("Reply body:"));
msg += "\n";
msg += data;
}
std::string redirected = tl::to_string (reply->attribute (QNetworkRequest::RedirectionTargetAttribute).toString ());
if (! redirected.empty ()) {
msg += "\n\n";
msg += tl::to_string (tr ("Redirected to: ")) + redirected;
}
return msg;
}
// ---------------------------------------------------------------
// InputHttpStream implementation
InputHttpStream::InputHttpStream (const std::string &url)
{
mp_data = new InputHttpStreamPrivateData (url);
@ -482,7 +449,9 @@ InputHttpStreamPrivateData::read (char *b, size_t n)
ec = int (mp_reply->error ());
}
throw HttpErrorException (em, ec, mp_reply);
QByteArray data = mp_reply->readAll ();
throw HttpErrorException (em, ec, tl::to_string (mp_reply->url ().toString ()), tl::to_string (data.constData (), (int)data.size ()));
}