Skip to content

Commit f7c065f

Browse files
ngxsonmglambda
authored andcommitted
server : add try..catch to places not covered by set_exception_handler (ggml-org#11620)
* server : add try..catch to places not covered by set_exception_handler * log_server_request: rm try catch, add reminder
1 parent a13d461 commit f7c065f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

examples/server/server.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,8 @@ static void log_server_request(const httplib::Request & req, const httplib::Resp
33533353
return;
33543354
}
33553355

3356+
// reminder: this function is not covered by httplib's exception handler; if someone does more complicated stuff, think about wrapping it in try-catch
3357+
33563358
LOG_INF("request: %s %s %s %d\n", req.method.c_str(), req.path.c_str(), req.remote_addr.c_str(), res.status);
33573359

33583360
LOG_DBG("request: %s\n", req.body.c_str());
@@ -3439,9 +3441,13 @@ int main(int argc, char ** argv) {
34393441
message = "Unknown Exception";
34403442
}
34413443

3442-
json formatted_error = format_error_response(message, ERROR_TYPE_SERVER);
3443-
LOG_WRN("got exception: %s\n", formatted_error.dump().c_str());
3444-
res_error(res, formatted_error);
3444+
try {
3445+
json formatted_error = format_error_response(message, ERROR_TYPE_SERVER);
3446+
LOG_WRN("got exception: %s\n", formatted_error.dump().c_str());
3447+
res_error(res, formatted_error);
3448+
} catch (const std::exception & e) {
3449+
LOG_ERR("got another exception: %s | while hanlding exception: %s\n", e.what(), message.c_str());
3450+
}
34453451
});
34463452

34473453
svr->set_error_handler([&res_error](const httplib::Request &, httplib::Response & res) {

0 commit comments

Comments
 (0)