AlexxIT/go2rtc · error

hap: can't read value

Error message

hap: can't read value: %v

What it means

ReadTLV8 requires the character's stored Value to be a base64 TLV8 string, but it holds a different type, so it cannot unmarshal into the target struct. Raised both in ReadTLV8 and ReadBool when the HAP characteristic value has an unexpected type.

Solutions

  1. Read the characteristic as its actual type (e.g. ReadBool) instead of TLV8
  2. Ensure the characteristic was populated from a TLV8/base64 source before calling ReadTLV8
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pkg/hap/character.go:133 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/c3fe48a61fa3a4f9. Report an issue: GitHub.

Appendix: source

Thrown at pkg/hap/character.go:133

		c.Value, err = tlv8.MarshalBase64(v)

	case "bool":
		switch v := v.(type) {
		case bool:
			c.Value = v
		case float64:
			c.Value = v != 0
		}
	}
	return
}

// ReadTLV8 value to right struct
func (c *Character) ReadTLV8(v any) (err error) {
	if s, ok := c.Value.(string); ok {
		return tlv8.UnmarshalBase64(s, v)
	}
	return fmt.Errorf("hap: can't read value: %v", v)
}

func (c *Character) ReadBool() (bool, error) {
	if v, ok := c.Value.(bool); ok {
		return v, nil
	}
	return false, fmt.Errorf("hap: can't read value: %v", c.Value)
}

func (c *Character) String() string {
	data, err := json.Marshal(c)
	if err != nil {
		return "ERROR"
	}
	return string(data)
}

View on GitHub (pinned to c245815e75)