Skip to content

Commit

Permalink
output_formatter: improve error message
Browse files Browse the repository at this point in the history
In some environments, these error messages are triggered often, without
being actual errors (client send command to Director and closes the
connection. In this case, the Director can't send the result back to the
client and issues this error).
With this patch, a debug message is issued instead of an error message.

Also instead of always stating, that the message might be too long,
it now checks the message size. Short messages are also show in the
output.
  • Loading branch information
joergsteffens committed Jun 8, 2017
1 parent ad9ac1d commit c66a739
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
34 changes: 27 additions & 7 deletions src/lib/output_formatter.c
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2016-2016 Planets Communications B.V.
Copyright (C) 2015-2016 Bareos GmbH & Co. KG
Copyright (C) 2015-2017 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -603,9 +603,19 @@ bool OUTPUT_FORMATTER::process_text_buffer()
if (string_length > 0) {
retval = send_func(send_ctx, result_message_plain->c_str());
if (!retval) {
error_msg.bsprintf("Failed to send message. Maybe result message to long?\n"
"Message length = %lld\n", string_length);
Emsg0(M_ERROR, 0, error_msg.c_str());
/*
* If send failed, include short messages in error messages.
* As messages can get quite long, don't show long messages.
*/
error_msg.bsprintf("Failed to send message (length=%lld). ", string_length);
if (string_length < max_message_length_shown_in_error) {
error_msg.strcat("Message: ");
error_msg.strcat(result_message_plain->c_str());
error_msg.strcat("\n");
} else {
error_msg.strcat("Maybe result message to long?\n");
}
Dmsg0(100, error_msg.c_str());
}
result_message_plain->strcpy("");
}
Expand Down Expand Up @@ -817,9 +827,19 @@ void OUTPUT_FORMATTER::json_finalize_result(bool result)
* send json string, on failure, send json error message
*/
if (!send_func(send_ctx, string)) {
error_msg.bsprintf("Failed to send result as json. Maybe result message to long?\n"
"Message length = %lld\n", string_length);
Emsg0(M_ERROR, 0, error_msg.c_str());
/*
* If send failed, include short messages in error messages.
* As messages can get quite long, don't show long messages.
*/
error_msg.bsprintf("Failed to send json message (length=%lld). ", string_length);
if (string_length < max_message_length_shown_in_error) {
error_msg.strcat("Message: ");
error_msg.strcat(string);
error_msg.strcat("\n");
} else {
error_msg.strcat("Maybe result message to long?\n");
}
Dmsg0(100, error_msg.c_str());
json_send_error_message(error_msg.c_str());
}
free(string);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/output_formatter.h
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2016-2016 Planets Communications B.V.
Copyright (C) 2015-2016 Bareos GmbH & Co. KG
Copyright (C) 2015-2017 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -117,6 +117,7 @@ class OUTPUT_FORMATTER : public SMARTALLOC {
alist *filters;
char *hidden_columns;
POOL_MEM *result_message_plain;
static const unsigned int max_message_length_shown_in_error = 1024;
#if HAVE_JANSSON
json_t *result_json;
alist *result_stack_json;
Expand Down

0 comments on commit c66a739

Please sign in to comment.