Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Dec 10, 2024
1 parent ab5cabc commit 395012f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/lib/pq/internal/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace tao::pq::internal

case SOCKET_ERROR: {
const int e = WSAGetLastError();
throw network_error( "WSAPoll() failed: " + errno_to_string( e ) );
throw network_error( std::format( "WSAPoll() failed: {}", errno_to_string( e ) ) );
}

default:
Expand Down Expand Up @@ -105,7 +105,7 @@ namespace tao::pq::internal
case -1: {
const int e = errno;
if( ( e != EINTR ) && ( e != EAGAIN ) ) {
throw network_error( "poll() failed: " + errno_to_string( e ) );
throw network_error( std::format( "poll() failed: ", errno_to_string( e ) ) );
}
return pq::poll::status::again;
}
Expand Down
9 changes: 5 additions & 4 deletions src/lib/pq/result_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <cstddef>
#include <cstring>
#include <format>
#include <stdexcept>
#include <string>

Expand All @@ -32,12 +33,12 @@ namespace tao::pq
[[nodiscard]] auto unescape_bytea( const char* value ) -> binary
{
if( ( value[ 0 ] != '\\' ) || ( value[ 1 ] != 'x' ) ) {
throw std::invalid_argument( "unescape BYTEA failed: " + std::string( value ) );
throw std::invalid_argument( std::format( "unescape BYTEA failed: {}", value ) );
}

const auto input = std::strlen( value );
if( input % 2 == 1 ) {
throw std::invalid_argument( "unescape BYTEA failed: " + std::string( value ) );
throw std::invalid_argument( std::format( "unescape BYTEA failed: {}", value ) );
}

const auto size = ( input / 2 ) - 1;
Expand Down Expand Up @@ -65,13 +66,13 @@ namespace tao::pq
return false;
}
}
throw std::runtime_error( "invalid value in tao::pq::result_traits<bool> for input: " + std::string( value ) );
throw std::runtime_error( std::format( "invalid value in tao::pq::result_traits<bool> for input: {}", value ) );
}

auto result_traits< char >::from( const char* value ) -> char
{
if( ( value[ 0 ] == '\0' ) || ( value[ 1 ] != '\0' ) ) {
throw std::runtime_error( "invalid value in tao::pq::result_traits<char> for input: " + std::string( value ) );
throw std::runtime_error( std::format( "invalid value in tao::pq::result_traits<char> for input: {}", value ) );
}
return value[ 0 ];
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pq/row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace tao::pq
}
}
}
throw std::out_of_range( "column not found: " + std::string( in_name ) );
throw std::out_of_range( std::format( "column not found: {}", static_cast< const char* >( in_name ) ) );
}

auto row::begin() const -> row::const_iterator
Expand Down
5 changes: 3 additions & 2 deletions src/test/getenv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// This is an internal header used for unit-tests.

#include <cstdlib>
#include <format>
#include <stdexcept>
#include <string>

Expand All @@ -27,7 +28,7 @@ namespace tao::pq::internal
const std::unique_ptr< char, decltype( &std::free ) > up( buf, &std::free );
return std::string( up.get(), sz );
}
throw std::runtime_error( "environment variable not found: " + name );
throw std::runtime_error( std::format( "environment variable not found: {}", name ) );
}

[[nodiscard]] inline auto getenv( const std::string& name, const std::string& default_value ) -> std::string
Expand All @@ -46,7 +47,7 @@ namespace tao::pq::internal
[[nodiscard]] inline auto getenv( const std::string& name ) -> std::string
{
const char* result = std::getenv( name.c_str() );
return ( result != nullptr ) ? result : throw std::runtime_error( "environment variable not found: " + name );
return ( result != nullptr ) ? result : throw std::runtime_error( std::format( "environment variable not found: {}", name ) );
}

[[nodiscard]] inline auto getenv( const std::string& name, const std::string& default_value ) -> std::string
Expand Down

0 comments on commit 395012f

Please sign in to comment.