0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd:Ⓜ️:vm: Elaborate eval error handlers; add room_id to error msgs.

This commit is contained in:
Jason Volk 2020-03-03 19:31:21 -08:00
parent e664ba22d8
commit 0907f5d6f2

View file

@ -234,45 +234,126 @@ try
return ret; return ret;
} }
catch(const error &e) // VM FAULT CODE catch(const vm::error &e) // VM FAULT CODE
{ {
const json::object &content{e.content};
const json::string &error
{
content["error"]
};
const auto &event_id
{
event.event_id?
string_view{event.event_id}:
"<edu>"_sv
};
const auto &room_id
{
eval.room_id?
eval.room_id:
json::get<"room_id"_>(event)?
string_view(json::get<"room_id"_>(event)):
"<edu>"_sv,
};
return handle_error return handle_error
( (
*eval.opts, e.code, *eval.opts, e.code,
"eval %s :%s", "eval %s %s :%s",
event.event_id? string_view{event.event_id}: "<edu>"_sv, event_id,
unquote(json::object(e.content).get("error")) room_id,
error
); );
} }
catch(const m::error &e) // GENERAL MATRIX ERROR catch(const m::error &e) // GENERAL MATRIX ERROR
{ {
const json::object &content{e.content};
const json::string error[]
{
content["errcode"],
content["error"]
};
const auto &event_id
{
event.event_id?
string_view{event.event_id}:
"<edu>"_sv
};
const auto &room_id
{
eval.room_id?
eval.room_id:
json::get<"room_id"_>(event)?
string_view(json::get<"room_id"_>(event)):
"<edu>"_sv,
};
return handle_error return handle_error
( (
*eval.opts, fault::GENERAL, *eval.opts, fault::GENERAL,
"eval %s (General Protection) :%s :%s :%s", "eval %s %s :%s :%s :%s",
event.event_id? string_view{event.event_id}: "<edu>"_sv, event_id,
room_id,
e.what(), e.what(),
unquote(json::object(e.content).get("errcode")), error[0],
unquote(json::object(e.content).get("error")) error[1]
); );
} }
catch(const ctx::interrupted &e) // INTERRUPTION catch(const ctx::interrupted &e) // INTERRUPTION
{ {
const auto &event_id
{
event.event_id?
string_view{event.event_id}:
"<edu>"_sv
};
const auto &room_id
{
eval.room_id?
eval.room_id:
json::get<"room_id"_>(event)?
string_view(json::get<"room_id"_>(event)):
"<edu>"_sv,
};
return handle_error return handle_error
( (
*eval.opts, fault::INTERRUPT, *eval.opts, fault::INTERRUPT,
"eval %s :%s", "eval %s %s :%s",
event.event_id? string_view{event.event_id}: "<edu>"_sv, event_id,
room_id,
e.what() e.what()
); );
} }
catch(const std::exception &e) // ALL OTHER ERRORS catch(const std::exception &e) // ALL OTHER ERRORS
{ {
const auto &event_id
{
event.event_id?
string_view{event.event_id}:
"<edu>"_sv
};
const auto &room_id
{
eval.room_id?
eval.room_id:
json::get<"room_id"_>(event)?
string_view(json::get<"room_id"_>(event)):
"<edu>"_sv,
};
return handle_error return handle_error
( (
*eval.opts, fault::GENERAL, *eval.opts, fault::GENERAL,
"eval %s (General Protection) :%s", "eval %s %s (General Protection) :%s",
event.event_id? string_view{event.event_id}: "<edu>"_sv, event_id,
room_id,
e.what() e.what()
); );
} }