8000 Use relative path in SourcedException by lukepalmer · Pull Request #555 · aeron-io/aeron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use relative path in SourcedException #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ endif(NOT CMAKE_BUILD_TYPE)

set(AERON_THIRDPARTY_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/thirdparty")

# relative file paths for use in exceptions
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")

##########################################################
# gmock usage

Expand Down
4 changes: 2 additions & 2 deletions aeron-client/src/main/cpp/util/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
namespace aeron { namespace util {

#ifdef _MSC_VER
#define SOURCEINFO __FUNCTION__, " : " __FILE__ " : " TOSTRING(__LINE__)
#define SOURCEINFO __FUNCTION__, " : " __FILENAME__ " : " TOSTRING(__LINE__)
#if _MSC_VER >= 1900
#define AERON_NOEXCEPT noexcept
#else
#define AERON_NOEXCEPT throw()
#endif
#else
#define SOURCEINFO __PRETTY_FUNCTION__, " : " __FILE__ " : " TOSTRING(__LINE__)
#define SOURCEINFO __PRETTY_FUNCTION__, " : " __FILENAME__ " : " TOSTRING(__LINE__)
#define AERON_NOEXCEPT noexcept
#endif

Expand Down
5 changes: 5 additions & 0 deletions aeron-client/src/test/cpp/util/TestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ std::string makeTempFileName()
#endif
}

void throwIllegalArgumentException()
{
throw util::IllegalArgumentException("Intentional IllegalArgumentException", SOURCEINFO);
}

}}

#endif //AERON_TESTUTILS_H
19 changes: 19 additions & 0 deletions aeron-client/src/test/cpp/util/UtilTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
#include <util/ScopeUtils.h>
#include <util/StringUtil.h>
#include <util/BitUtil.h>
#include "TestUtils.h"

#include <gtest/gtest.h>
#include <gmock/gmock.h>


using namespace aeron::util;
using namespace aeron::test;

TEST(utilTests, scopeTest)
{
Expand Down Expand Up @@ -103,3 +107,18 @@ TEST(utilTests, numberOfTrailingZeroes)
EXPECT_EQ(BitUtil::numberOfTrailingZeroes<std::uint32_t>(0xFFFF0000), 16);
EXPECT_EQ(BitUtil::numberOfTrailingZeroes<std::uint32_t>(0x00000001), 0);
}

TEST(utilTests, sourcedExceptionContainsRelativePath)
{
EXPECT_THROW({
try
{
throwIllegalArgumentException();
}
catch(const SourcedException& e)
{
EXPECT_THAT(e.where(), ::testing::HasSubstr(" aeron-client/"));
throw;
}
}, SourcedException);
}
2 changes: 1 addition & 1 deletion aeron-driver/src/main/c/aeron_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ int aeron_agent_init(
{
int err_code = errno;

aeron_set_err(err_code, "%s:%d: %s", __FILE__, __LINE__, strerror(err_code));
aeron_set_err(err_code, "%s:%d: %s", __FILENAME__, __LINE__, strerror(err_code));
return -1;
}
memcpy((char *)runner->role_name, role_name, role_name_length);
Expand Down
18 changes: 9 additions & 9 deletions aeron-driver/src/main/c/aeron_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int aeron_report_existing_errors(aeron_mapped_file_t *cnc_map, const char *aeron
{
int errcode = errno;

aeron_set_err(errcode, "%s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "%s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
result = -1;
}
}
Expand Down Expand Up @@ -324,7 +324,7 @@ int aeron_driver_validate_sufficient_socket_buffer_lengths(aeron_driver_t *drive
{
int errcode = errno;

aeron_set_err(errcode, "socket %s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "socket %s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
goto cleanup;
}

Expand All @@ -334,7 +334,7 @@ int aeron_driver_validate_sufficient_socket_buffer_lengths(aeron_driver_t *drive
{
int errcode = errno;

aeron_set_err(errcode, "getsockopt(SO_SNDBUF) %s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "getsockopt(SO_SNDBUF) %s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
goto cleanup;
}

Expand All @@ -344,7 +344,7 @@ int aeron_driver_validate_sufficient_socket_buffer_lengths(aeron_driver_t *drive
{
int errcode = errno;

aeron_set_err(errcode, "getsockopt(SO_RCVBUF) %s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "getsockopt(SO_RCVBUF) %s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
goto cleanup;
}

Expand All @@ -359,7 +359,7 @@ int aeron_driver_validate_sufficient_socket_buffer_lengths(aeron_driver_t *drive
{
int errcode = errno;

aeron_set_err(errcode, "setsockopt(SO_SNDBUF) %s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "setsockopt(SO_SNDBUF) %s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
goto cleanup;
}

Expand All @@ -368,7 +368,7 @@ int aeron_driver_validate_sufficient_socket_buffer_lengths(aeron_driver_t *drive
{
int errcode = errno;

aeron_set_err(errcode, "getsockopt(SO_SNDBUF) %s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "getsockopt(SO_SNDBUF) %s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
goto cleanup;
}

Expand All @@ -393,7 +393,7 @@ int aeron_driver_validate_sufficient_socket_buffer_lengths(aeron_driver_t *drive
{
int errcode = errno;

aeron_set_err(errcode, "setsockopt(SO_RCVBUF) %s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "setsockopt(SO_RCVBUF) %s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
goto cleanup;
}

Expand All @@ -402,7 +402,7 @@ int aeron_driver_validate_sufficient_socket_buffer_lengths(aeron_driver_t *drive
{
int errcode = errno;

aeron_set_err(errcode, "getsockopt(SO_RCVBUF) %s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "getsockopt(SO_RCVBUF) %s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
goto cleanup;
}

Expand Down Expand Up @@ -536,7 +536,7 @@ int aeron_driver_init(aeron_driver_t **driver, aeron_driver_context_t *context)
{
int errcode = errno;

aeron_set_err(errcode, "%s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "%s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
goto error;
}

Expand Down
2 changes: 1 addition & 1 deletion aeron-driver/src/main/c/aeron_driver_receiver.c
F438
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int aeron_driver_receiver_init(
{
int errcode = errno;

aeron_set_err(errcode, "%s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "%s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion aeron-driver/src/main/c/aeron_driver_sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int aeron_driver_sender_init(
{
int errcode = errno;

aeron_set_err(errcode, "%s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "%s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions aeron-driver/src/main/c/aeron_system_counters.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int aeron_system_counters_init(aeron_system_counters_t *counters, aeron_counters
{
if (NULL == counters || NULL == manager)
{
aeron_set_err(EINVAL, "%s:%d: %s", __FILE__, __LINE__, strerror(EINVAL));
aeron_set_err(EINVAL, "%s:%d: %s", __FILENAME__, __LINE__, strerror(EINVAL));
return -1;
}

Expand All @@ -63,7 +63,7 @@ int aeron_system_counters_init(aeron_system_counters_t *counters, aeron_counters
{
int errcode = errno;

aeron_set_err(errcode, "%s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "%s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ inline int aeron_str_to_ptr_hash_map_init(
{
int errcode = errno;

aeron_set_err(errcode, "%s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "%s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
return -1;
}

if (aeron_alloc((void **)&map->values, (capacity * sizeof(void *))) < 0)
{
int errcode = errno;

aeron_set_err(errcode, "%s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "%s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
return -1;
}

Expand Down Expand Up @@ -116,15 +116,15 @@ inline int aeron_str_to_ptr_hash_map_rehash(aeron_str_to_ptr_hash_map_t *map, si
{
int errcode = errno;

aeron_set_err(errcode, "%s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "%s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
return -1;
}

if (aeron_alloc((void **)&tmp_values, (new_capacity * sizeof(void *))) < 0)
{
int errcode = errno;

aeron_set_err(errcode, "%s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "%s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
return -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int aeron_broadcast_transmitter_init(volatile aeron_broadcast_transmitter_t *tra
}
else
{
aeron_set_err(EINVAL, "%s:%d: %s", __FILE__, __LINE__, strerror(EINVAL));
aeron_set_err(EINVAL, "%s:%d: %s", __FILENAME__, __LINE__, strerror(EINVAL));
}

return result;
Expand Down
6 changes: 3 additions & 3 deletions aeron-driver/src/main/c/concurrent/aeron_counters_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int aeron_counters_manager_init(
}
else
{
aeron_set_err(EINVAL, "%s:%d: %s", __FILE__, __LINE__, strerror(EINVAL));
aeron_set_err(EINVAL, "%s:%d: %s", __FILENAME__, __LINE__, strerror(EINVAL));
}

return result;
Expand All @@ -71,13 +71,13 @@ int32_t aeron_counters_manager_allocate(

if ((counter_id * AERON_COUNTERS_MANAGER_VALUE_LENGTH) + AERON_COUNTERS_MANAGER_VALUE_LENGTH > manager->values_length)
{
aeron_set_err(EINVAL, "%s:%d: %s", __FILE__, __LINE__, strerror(EINVAL));
aeron_set_err(EINVAL, "%s:%d: %s", __FILENAME__, __LINE__, strerror(EINVAL));
return -1;
}

if ((counter_id * AERON_COUNTERS_MANAGER_METADATA_LENGTH) + AERON_COUNTERS_MANAGER_METADATA_LENGTH > manager->metadata_length)
{
aeron_set_err(EINVAL, "%s:%d: %s", __FILE__, __LINE__, strerror(EINVAL));
aeron_set_err(EINVAL, "%s:%d: %s", __FILENAME__, __LINE__, strerror(EINVAL));
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions aeron-driver/src/main/c/concurrent/aeron_distinct_error_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ int aeron_distinct_error_log_init(
{
if (NULL == log || NULL == clock || NULL == linger)
{
aeron_set_err(EINVAL, "%s:%d: %s", __FILE__, __LINE__, strerror(EINVAL));
aeron_set_err(EINVAL, "%s:%d: %s", __FILENAME__, __LINE__, strerror(EINVAL));
return -1;
}

if (aeron_alloc((void **)&log->observation_list, sizeof(aeron_distinct_error_log_observation_list_t)) < 0)
{
int errcode = errno;

aeron_set_err(errcode, "%s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "%s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion aeron-driver/src/main/c/concurrent/aeron_mpsc_rb.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int aeron_mpsc_rb_init(volatile aeron_mpsc_rb_t *ring_buffer, void *buffer, size
}
else
{
aeron_set_err(EINVAL, "%s:%d: %s", __FILE__, __LINE__, strerror(EINVAL));
aeron_set_err(EINVAL, "%s:%d: %s", __FILENAME__, __LINE__, strerror(EINVAL));
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ int aeron_udp_channel_transport_get_so_rcvbuf(aeron_udp_channel_transport_t *tra
{
int errcode = errno;

aeron_set_err(errcode, "getsockopt(SO_RCVBUF) %s:%d: %s", __FILE__, __LINE__, strerror(errcode));
aeron_set_err(errcode, "getsockopt(SO_RCVBUF) %s:%d: %s", __FILENAME__, __LINE__, strerror(errcode));
return -1;
}

Expand Down
Loading
0