From 84fef41de6998c8a57e0cbfe9507cec4284d36de Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 13 Dec 2025 07:29:35 +0000 Subject: [PATCH] Refactor error handling in readSequence to use ErrorExpectedSequenceItem Replaced log.Println and ad-hoc error formatting with a new exported error variable ErrorExpectedSequenceItem. This improves error handling consistency and allows callers to programmatically check for this specific error condition. --- read.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/read.go b/read.go index 5366c332..e1cd86a8 100644 --- a/read.go +++ b/read.go @@ -34,6 +34,7 @@ var ( ErrorExpectedEvenLength = errors.New("field length is not even, in violation of DICOM spec") ErrorExpectedDefinedLength = errors.New("unable to read field of undefined length") ErrorExpectedSequenceDelimitation = errors.New("expected to find sequence delimitation item (fffe,e0dd)") + ErrorExpectedSequenceItem = errors.New("expected to find item element in sequence") ) // reader is responsible for mid-level dicom parsing capabilities, like @@ -600,9 +601,7 @@ func (r *reader) readSequence(t tag.Tag, vr string, vl uint32, d *Dataset) (Valu } if subElement.Tag != tag.Item || subElement.Value.ValueType() != SequenceItem { // This is an error, should be an Item! - // TODO: use error var - log.Println("Tag is ", subElement.Tag) - return nil, fmt.Errorf("readSequence: error, non item element found in sequence. got: %v", subElement) + return nil, fmt.Errorf("readSequence: error, %w. got: %v", ErrorExpectedSequenceItem, subElement) } // Append the Item element's dataset of elements to this Sequence's sequencesValue.