OpenNHP/opennhp · error
nhp server length is too long
Error message
nhp server length is too long
What it means
SetNhpServer stores the NHP server identity into the ZtdoHeader. The header reserves a single byte (NhpServerLen) for the server string length, capping it at NhpServerMaxSize bytes. Longer strings return this error instead of silently truncating.
Solutions
- Shorten the nhp server string (use a shorter hostname; check it against NhpServerMaxSize bytes, not characters)
- Move port/scheme out of the field if possible
- Validate the length before constructing the header and fail config load early with a clearer message
Example fix
// before
if len(nhpServer) > NhpServerMaxSize {
return fmt.Errorf("nhp server length is too long")
}
// after
if len(nhpServer) > NhpServerMaxSize {
return fmt.Errorf("nhp server %q is %d bytes, max is %d", nhpServer, len(nhpServer), NhpServerMaxSize)
} Defensive patterns
Strategy: validation
Validate before calling
if len(nhpServer) > NhpServerMaxSize {
return fmt.Errorf("nhp server must be at most %d bytes, got %d", NhpServerMaxSize, len(nhpServer))
} Try / catch
if err := header.SetNhpServer(server); err != nil {
if strings.Contains(err.Error(), "nhp server length is too long") {
// shorten hostname or reject config
}
return err
} Prevention
- Validate server string length (in bytes) at config load time
- Use short hostnames; avoid embedding scheme and port in the field
- Watch IPv6 literals, which consume many bytes
When it happens
Trigger: Calling ZtdoHeader.SetNhpServer with a string longer than NhpServerMaxSize bytes (nhp/core/ztdo/ztdo.go:121). Called from runApp and recursively via SetNhpServer wrappers.
Common situations: Configuring long FQDNs or "host:port" with IPv6 literal addresses exceeding the byte limit; concatenating scheme + host + port into the server field.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- unsupported protocol
- cluster instance # : must set either Host or Ip
- cluster instance # : invalid port
- AuthServiceId is required
- invalid digit count
AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07).
Data as JSON: /api/errors/16a8caec5b95df0b.
Report an issue: GitHub.
Appendix: source
Thrown at nhp/core/ztdo/ztdo.go:121
// generate uuid
uuid := uuid.New()
header.ObjectID = [ObjectIDSize]byte(uuid)
// User first 4 bytes to set magic number
header.MagicNumber = [MagicNumberSize]byte(uuid[0:4])
}
func (header *ZtdoHeader) GetObjectID() string {
return uuid.UUID(header.ObjectID).String()
}
func (header *ZtdoHeader) SetVersion() {
header.Version = [VersionSize]byte{0x00, 0x01}
}
func (header *ZtdoHeader) SetNhpServer(nhpServer string) error {
if len(nhpServer) > NhpServerMaxSize {
return fmt.Errorf("nhp server length is too long")
}
header.NhpServerLen[0] = byte(len(nhpServer))
header.NhpServer = []byte(nhpServer)
return nil
}
// SetMetadata supports variable length of metadata
func (header *ZtdoHeader) SetMetadata(metadata string) error {
header.Metadata = []ZtdoMetadata{}
totalLen := len(metadata)
chunkNum := totalLen / MetadataChunkMaxSize
for i := 0; i < chunkNum; i++ {
chunk := metadata[i*MetadataChunkMaxSize : (i+1)*MetadataChunkMaxSize]
chunkEncodedLen, err := encodeMetadataLength(len(chunk), true)View on GitHub (pinned to 6e04ca5ff0)