Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion profcheck/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (c ConformanceChecker) checkStringTable(strTable []string) error {

func (c ConformanceChecker) checkAttributeTable(attrTable []*profiles.KeyValueAndUnit, lenStrTable int) error {
var errs error
if err := checkZeroVal(attrTable); err != nil {
if err := checkAttributeTableZeroVal(attrTable); err != nil {
errs = errors.Join(errs, err)
}
for pos, kvu := range attrTable {
Expand All @@ -346,6 +346,25 @@ func (c ConformanceChecker) checkAttributeTable(attrTable []*profiles.KeyValueAn
return errs
}

// checkAttributeTableZeroVal verifies that the AttributeTable meets Profiles
// dictionary conventions: the slice is not empty and the first entry has zero
// key and unit indices and the value field holds nil as value.
func checkAttributeTableZeroVal(attrTable []*profiles.KeyValueAndUnit) error {
if len(attrTable) == 0 {
return errors.New("empty table, must have at least zero value entry")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return errors.New("empty table, must have at least zero value entry")
return errors.New("empty attribute table, must have at least zero value entry")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with checkZeroVal() I'm keeping the error message.

Copy link
Copy Markdown
Member

@christos68k christos68k Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case, we can do better as the primary utility of this logic is to point out violations. So all these empty table errors (not just attribute table) can be a lot better in mentioning the actual table that violates the spec (rather than "empty table" which leaves the user manually having to inspect data to figure out the source of the violation).

We don't have to do that in this PR, LMK what you think.

}
first := attrTable[0]
if first.KeyStrindex != 0 || first.UnitStrindex != 0 {
return fmt.Errorf("first attribute must have zero key/unit indices, got KeyStrindex=%d, UnitStrindex=%d",
first.KeyStrindex, first.UnitStrindex)
}
value := first.GetValue()
if value != nil && value.Value != nil {
return fmt.Errorf("first attribute value must be nil, got %v", value)
}
return nil
}

func (c ConformanceChecker) checkStackTable(stackTable []*profiles.Stack, lenLocTable int) error {
var errs error
if err := checkZeroVal(stackTable); err != nil {
Expand Down