aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-12-02 03:19:37 +0900
committerOphestra <cat@gensokyo.uk>2025-12-02 03:19:37 +0900
commit7bc73afaddc543bbc0e798b4e98b3e91ea289726 (patch)
tree7e27cbfdc532b633d2d3357cf2db67eb70494739 /internal
parent647aa9d02fb275c47ae00c552977d42013888a6b (diff)
internal/pipewire: wrap EOF error for deserialisation
The io.ErrUnexpectedEOF error can be returned from multiple places. This change eases error handling. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal')
-rw-r--r--internal/pipewire/pod.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/internal/pipewire/pod.go b/internal/pipewire/pod.go
index 88a49e82..9c74bf3e 100644
--- a/internal/pipewire/pod.go
+++ b/internal/pipewire/pod.go
@@ -260,6 +260,12 @@ func (e *InvalidUnmarshalError) Error() string {
return "attempting to unmarshal to nil " + e.Type.String()
}
+// UnexpectedEOFError is returned when EOF was encountered in the middle of decoding POD data.
+type UnexpectedEOFError struct{}
+
+func (UnexpectedEOFError) Unwrap() error { return io.ErrUnexpectedEOF }
+func (UnexpectedEOFError) Error() string { return "unexpected EOF decoding POD data" }
+
// Unmarshal parses the PipeWire POD encoded data and stores the result
// in the value pointed to by v. If v is nil or not a pointer,
// Unmarshal returns an [InvalidUnmarshalError].
@@ -386,7 +392,7 @@ func unmarshalValue(data []byte, v reflect.Value, wireSizeP *Word) error {
case reflect.Pointer:
if len(data) < SizePrefix {
- return io.ErrUnexpectedEOF
+ return UnexpectedEOFError{}
}
switch binary.NativeEndian.Uint32(data[SizeSPrefix:]) {
case SPA_TYPE_None:
@@ -407,7 +413,7 @@ func unmarshalValue(data []byte, v reflect.Value, wireSizeP *Word) error {
// string size, one extra NUL byte
size := int(*wireSizeP)
if len(data) < size {
- return io.ErrUnexpectedEOF
+ return UnexpectedEOFError{}
}
// the serialised strings still include NUL termination
@@ -443,7 +449,7 @@ func (u *UnexpectedTypeError) Error() string {
// An expected size of zero skips further bounds checks.
func unmarshalCheckTypeBounds(data *[]byte, t Word, sizeP *Word) error {
if len(*data) < SizePrefix {
- return io.ErrUnexpectedEOF
+ return UnexpectedEOFError{}
}
wantSize := *sizeP
@@ -454,7 +460,7 @@ func unmarshalCheckTypeBounds(data *[]byte, t Word, sizeP *Word) error {
return &InconsistentSizeError{gotSize, wantSize}
}
if len(*data)-SizePrefix < int(gotSize) {
- return io.ErrUnexpectedEOF
+ return UnexpectedEOFError{}
}
gotType := binary.NativeEndian.Uint32((*data)[SizeSPrefix:])