Skip to content

Redis exceptions: add proper what() messages#10727

Merged
julianbrost merged 3 commits intomasterfrom
icingadb-missing-exception-messages
Mar 31, 2026
Merged

Redis exceptions: add proper what() messages#10727
julianbrost merged 3 commits intomasterfrom
icingadb-missing-exception-messages

Conversation

@julianbrost
Copy link
Copy Markdown
Member

@julianbrost julianbrost commented Feb 23, 2026

RedisDisconnected::what() and RedisProtocolError::what() always returned an empty string. Similarly, BadRedisType::what() and BadRedisInt::what() only return the value that couldn't be parsed without any information about the exception type. If only what() is used when printing the exception, as it's typical, this results in unhelpful log messages like the following when simply stopping the Redis server:

[2026-02-23 14:33:33 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten: Connection reset by peer [system:104 at /usr/include/boost/asio/detail/reactive_socket_recv_op.hpp:134 in function 'do_complete']
[2026-02-23 14:33:33 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten:
[2026-02-23 14:33:33 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten:
[2026-02-23 14:33:33 +0100] critical/IcingaDB: Cannot connect to redis-1:6379: Connection refused [system:111 at /usr/include/boost/asio/detail/reactive_socket_connect_op.hpp:98 in function 'do_complete']

This commit changes these messages so that something like "Redis disconnected", "Redis protocol error: bad int: foo", or "Redis protocol error: bad type: ?" is returned. In doing so, it also removes a member of type std::vector in BadRedisInt as this is unsafe to use in exceptions (it violates the requirement that copy constructor and assignment must be nothrow, see https://en.cppreference.com/w/cpp/error/exception.html#Standard_exception_requirements).

With this commit, the log messages are now a bit more helpful:

[2026-02-23 15:08:23 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten: Connection reset by peer [system:104 at /usr/include/boost/asio/detail/reactive_socket_recv_op.hpp:134 in function 'do_complete']
[2026-02-23 15:08:23 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten: Redis disconnected
[2026-02-23 15:08:23 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten: Redis disconnected
[2026-02-23 15:08:23 +0100] critical/IcingaDB: Cannot connect to redis-1:6379: Connection refused [system:111 at /usr/include/boost/asio/detail/reactive_socket_connect_op.hpp:98 in function 'do_complete']

Additionally, some minor cleanup around the exceptions is done: use BOOST_THROW_EXCEPTION() and remove redundant inline specifiers.

@julianbrost julianbrost added bug Something isn't working area/icingadb New backend labels Feb 23, 2026
@cla-bot cla-bot bot added the cla/signed label Feb 23, 2026
Copy link
Copy Markdown
Contributor

@jschmidt-icinga jschmidt-icinga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few suggestions. Pretty straight forward otherwise.

Comment thread lib/icingadb/redisconnection.hpp Outdated
Comment thread lib/icingadb/redisconnection.hpp Outdated
Comment thread lib/icingadb/redisconnection.hpp Outdated
@jschmidt-icinga jschmidt-icinga added this to the 2.16.0 milestone Mar 17, 2026
@julianbrost julianbrost force-pushed the icingadb-missing-exception-messages branch from fe518b2 to b6a4963 Compare March 27, 2026 15:23
@julianbrost
Copy link
Copy Markdown
Member Author

In addition to what was requests/discussed in the review, I've also added some more explicit for constructors with a single argument.

Copy link
Copy Markdown
Contributor

@jschmidt-icinga jschmidt-icinga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than one last nitpick this looks fine now.

Comment thread lib/icingadb/redisconnection.hpp Outdated
Comment on lines +313 to +315
RedisDisconnected()
{
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constructor can be defaulted or just removed.

RedisDisconnected::what() and RedisProtocolError::what() always returned an
empty string. Similarly, BadRedisType::what() and BadRedisInt::what() only
return the value that couldn't be parsed without any information about the
exception type. If only what() is used when printing the exception, as it's
typical, this results in unhelpful log messages like the following when simply
stopping the Redis server:

    [2026-02-23 14:33:33 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten: Connection reset by peer [system:104 at /usr/include/boost/asio/detail/reactive_socket_recv_op.hpp:134 in function 'do_complete']
    [2026-02-23 14:33:33 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten:
    [2026-02-23 14:33:33 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten:
    [2026-02-23 14:33:33 +0100] critical/IcingaDB: Cannot connect to redis-1:6379: Connection refused [system:111 at /usr/include/boost/asio/detail/reactive_socket_connect_op.hpp:98 in function 'do_complete']

This commit changes these messages so that something like "Redis disconnected",
"Redis protocol error: bad int: foo", or "Redis protocol error: bad type: ?" is
returned. In doing so, it also removes a member of type std::vector<char> in
BadRedisInt as this is unsafe to use in exceptions (it violates the requirement
that copy constructor and assignment must be nothrow, see
https://en.cppreference.com/w/cpp/error/exception.html#Standard_exception_requirements).

With this commit, the log messages are now a bit more helpful:

    [2026-02-23 15:08:23 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten: Connection reset by peer [system:104 at /usr/include/boost/asio/detail/reactive_socket_recv_op.hpp:134 in function 'do_complete']
    [2026-02-23 15:08:23 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten: Redis disconnected
    [2026-02-23 15:08:23 +0100] critical/IcingaDB: Error during receiving the response to a query which has been fired and forgotten: Redis disconnected
    [2026-02-23 15:08:23 +0100] critical/IcingaDB: Cannot connect to redis-1:6379: Connection refused [system:111 at /usr/include/boost/asio/detail/reactive_socket_connect_op.hpp:98 in function 'do_complete']
Use it for consistency, as requested in the PR review.
Remove them as they are redundant, as requested in the PR review.
@julianbrost julianbrost force-pushed the icingadb-missing-exception-messages branch from b6a4963 to 2077645 Compare March 27, 2026 16:03
@julianbrost
Copy link
Copy Markdown
Member Author

I've also fixed one more clang-tidy warning by marking what() as [[nodiscard]].

Copy link
Copy Markdown
Contributor

@jschmidt-icinga jschmidt-icinga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now.

@julianbrost julianbrost merged commit 4f13651 into master Mar 31, 2026
37 of 52 checks passed
@julianbrost julianbrost deleted the icingadb-missing-exception-messages branch March 31, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/icingadb New backend bug Something isn't working cla/signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants