| 352 | |
| 353 | |
| 354 | int main(const std::vector<std::string> & /*args*/) override |
| 355 | { |
| 356 | try |
| 357 | { |
| 358 | return mainImpl(); |
| 359 | } |
| 360 | catch (const Exception & e) |
| 361 | { |
| 362 | bool print_stack_trace = config().getBool("stacktrace", false); |
| 363 | |
| 364 | std::string text = e.displayText(); |
| 365 | |
| 366 | /** If exception is received from server, then stack trace is embedded in message. |
| 367 | * If exception is thrown on client, then stack trace is in separate field. |
| 368 | */ |
| 369 | |
| 370 | auto embedded_stack_trace_pos = text.find("Stack trace"); |
| 371 | if (std::string::npos != embedded_stack_trace_pos && !print_stack_trace) |
| 372 | text.resize(embedded_stack_trace_pos); |
| 373 | |
| 374 | std::cerr << "Code: " << e.code() << ". " << text << std::endl << std::endl; |
| 375 | |
| 376 | /// Don't print the stack trace on the client if it was logged on the server. |
| 377 | /// Also don't print the stack trace in case of network errors. |
| 378 | if (print_stack_trace && e.code() != ErrorCodes::NETWORK_ERROR && std::string::npos == embedded_stack_trace_pos) |
| 379 | { |
| 380 | std::cerr << "Stack trace:" << std::endl << e.getStackTraceString(); |
| 381 | } |
| 382 | |
| 383 | /// If exception code isn't zero, we should return non-zero return code anyway. |
| 384 | return e.code() ? e.code() : -1; |
| 385 | } |
| 386 | catch (...) |
| 387 | { |
| 388 | std::cerr << getCurrentExceptionMessage(false) << std::endl; |
| 389 | return getCurrentExceptionCode(); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /// Should we celebrate a bit? |
| 394 | static bool isNewYearMode() |
nothing calls this directly
no test coverage detected