From 0001ec37b4aebbf801961eabc7b3a168267d0e6e Mon Sep 17 00:00:00 2001 From: Robert Sinclair <0wwafa@gmail.com> Date: Thu, 30 May 2024 17:09:15 +0300 Subject: [PATCH] Update server.cpp Catched exceptions in server load. --- examples/server/server.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/server/server.cpp b/examples/server/server.cpp index e9904263d..75076ed52 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -3028,13 +3028,26 @@ int main(int argc, char ** argv) { log_data["api_key"] = "api_key: " + std::to_string(sparams.api_keys.size()) + " keys loaded"; } - // load the model - if (!ctx_server.load_model(params)) { - state.store(SERVER_STATE_ERROR); - return 1; - } else { + try { + // Attempt to load the model + if (!ctx_server.load_model(params)) { + LOG_ERROR("unable to load model", {{"error", "Load model failed"}}); + state.store(SERVER_STATE_ERROR); + return 1; + } + + // Initialize the server context if the model is loaded successfully ctx_server.init(); state.store(SERVER_STATE_READY); + + } catch (const std::exception &e) { + // Catch known standard exceptions + LOG_ERROR("unable to load model", {{"error", e.what()}}); + exit(1); + } catch (...) { + // Catch all other exceptions + LOG_ERROR("unable to load model", {{"error", "Unknown Exception"}}); + exit(1); } LOG_INFO("model loaded", {});