Skip to content

discv5/discv5_error.hpp

Namespaces

Name
discv5

Types

Name
enum class discv5Error { kEnrMissingPrefix, kEnrBase64DecodeFailed, kEnrRlpDecodeFailed, kEnrTooShort, kEnrTooLarge, kEnrSignatureInvalid, kEnrSignatureWrongSize, kEnrMissingSecp256k1Key, kEnrInvalidSecp256k1Key, kEnrMissingAddress, kEnrInvalidIp, kEnrInvalidIp6, kEnrInvalidUdpPort, kEnrInvalidEthEntry, kEnrIdentityUnknown, kEnodeUriMalformed, kEnodeHexPubkeyInvalid, kContextCreationFailed, kCrawlerAlreadyRunning, kCrawlerNotRunning, kNetworkSendFailed, kNetworkReceiveFailed}
Enumeration of all error conditions that can be returned by the discv5 module.
template <typename T >
using outcome::result< T, discv5Error, outcome::policy::all_narrow >
Result
Result type for discv5 operations that return a value.
using outcome::result< void, discv5Error, outcome::policy::all_narrow > VoidResult
Result type for discv5 operations that return nothing on success.

Functions

Name
const char * to_string(discv5Error error)
Convert a discv5Error code to a human-readable C string.

Types Documentation

enum discv5Error

Enumerator Value Description
kEnrMissingPrefix Input string does not start with "enr:".
kEnrBase64DecodeFailed Base64url decode of the ENR body failed.
kEnrRlpDecodeFailed RLP decode of the ENR record failed.
kEnrTooShort RLP list has too few items (need ≥ 2).
kEnrTooLarge Serialised ENR exceeds kEnrMaxBytes (300) bytes.
kEnrSignatureInvalid Signature verification failed.
kEnrSignatureWrongSize Signature field is not 64 bytes.
kEnrMissingSecp256k1Key Required "secp256k1" field is absent.
kEnrInvalidSecp256k1Key secp256k1 field cannot be parsed as pubkey
kEnrMissingAddress Neither "ip" nor "ip6" field is present.
kEnrInvalidIp "ip" field is not exactly 4 bytes
kEnrInvalidIp6 "ip6" field is not exactly 16 bytes
kEnrInvalidUdpPort "udp" field value is zero or out of range
kEnrInvalidEthEntry "eth" entry could not be decoded as [hash, next]
kEnrIdentityUnknown "id" field does not name a supported scheme
kEnodeUriMalformed enode:// URI could not be parsed
kEnodeHexPubkeyInvalid Hex-encoded pubkey in enode URI has wrong length/chars.
kContextCreationFailed Failed to create secp256k1 context.
kCrawlerAlreadyRunning start() called while crawler is active
kCrawlerNotRunning stop() called on an idle crawler
kNetworkSendFailed UDP send operation failed.
kNetworkReceiveFailed UDP receive operation failed.

Enumeration of all error conditions that can be returned by the discv5 module.

Follows the same idiom as discv4::discv4Error: a plain enum class used as the error type in outcome::result.

using Result

template <typename T >
using discv5::Result = outcome::result<T, discv5Error, outcome::policy::all_narrow>;

Result type for discv5 operations that return a value.

Template Parameters:

  • T Success value type.

using VoidResult

using discv5::VoidResult = outcome::result<void, discv5Error, outcome::policy::all_narrow>;

Result type for discv5 operations that return nothing on success.

Functions Documentation

function to_string

const char * to_string(
    discv5Error error
)

Convert a discv5Error code to a human-readable C string.

Parameters:

  • error The error code to describe.

Return: A static null-terminated string. Never returns nullptr.

Source code

// Copyright 2025 GeniusVentures
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <boost/outcome/result.hpp>
#include <boost/outcome/try.hpp>

namespace discv5
{

namespace outcome = BOOST_OUTCOME_V2_NAMESPACE;

// ---------------------------------------------------------------------------
// Error enumeration
// ---------------------------------------------------------------------------

enum class discv5Error
{
    kEnrMissingPrefix,            
    kEnrBase64DecodeFailed,       
    kEnrRlpDecodeFailed,          
    kEnrTooShort,                 
    kEnrTooLarge,                 
    kEnrSignatureInvalid,         
    kEnrSignatureWrongSize,       
    kEnrMissingSecp256k1Key,      
    kEnrInvalidSecp256k1Key,      
    kEnrMissingAddress,           
    kEnrInvalidIp,                
    kEnrInvalidIp6,               
    kEnrInvalidUdpPort,           
    kEnrInvalidEthEntry,          
    kEnrIdentityUnknown,          
    kEnodeUriMalformed,           
    kEnodeHexPubkeyInvalid,       
    kContextCreationFailed,       
    kCrawlerAlreadyRunning,       
    kCrawlerNotRunning,           
    kNetworkSendFailed,           
    kNetworkReceiveFailed,        
};

// ---------------------------------------------------------------------------
// Result alias templates
// ---------------------------------------------------------------------------

template <typename T>
using Result = outcome::result<T, discv5Error, outcome::policy::all_narrow>;

using VoidResult = outcome::result<void, discv5Error, outcome::policy::all_narrow>;

// ---------------------------------------------------------------------------
// Helper
// ---------------------------------------------------------------------------

const char* to_string(discv5Error error) noexcept;

} // namespace discv5

Updated on 2026-04-13 at 23:22:46 -0700