fix(enumerator): treat an empty sysfs attribute as empty, not an error#220
Merged
Merged
Conversation
readLine returned io.EOF for a present-but-empty USB sysfs attribute file (serial/manufacturer/product). parseUSBSysFS reads those as required fields, so a single device with a blank attribute made the whole GetDetailedPortsList() fail. Return an empty string for an empty file, mirroring how an absent attribute is already handled via os.IsNotExist.
cmaglie
approved these changes
May 25, 2026
Member
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Linux,
enumerator.readLine(enumerator/usb_linux.go) returnsio.EOFwhen a USB sysfs attribute file exists but is empty (zero bytes).bufio.Reader.ReadLine()returns("", io.EOF)for an empty file, andreadLinepasses that EOF through.parseUSBSysFSreadsidVendor,idProduct,serial,manufacturerandproductas required fields and propagates the error, so a single USB device that exposes one of these attributes but leaves it blank (some devices ship with an emptyserial/manufacturer/productstring descriptor) makes the entireGetDetailedPortsList()call fail — no ports are returned at all.An absent attribute is already handled gracefully (
os.IsNotExist→"", nil); an empty one was not.Fix
Return
("", nil)whenReadLinereportsio.EOF, treating an empty attribute the same as a missing one.Tests
Added
enumerator/usb_linux_test.go— all hardware-free (temp files, no real device/sysfs):TestReadLineEmptyFile— empty file →"", not an error.TestParseUSBSysFSEmptySerial— a device dir with a present-but-emptyserial/manufacturerparses successfully (emptySerialNumber).TestReadLineMissingFile/TestReadLineContent— regression guards (absent file, normal content with/without trailing newline).Both new tests fail before the change (return/propagate
io.EOF) and pass after.go test -race ./...stays green (verified on Linux).