larksuite/cli · error

duplicate attribute %q

Error message

duplicate attribute %q

What it means

Guard in the HTML-block tag parser: an XML start element declares the same attribute name twice (after lowercasing), which cannot be represented in the attribute map. Wraps into a typed validation error by the caller.

Source

Thrown at shortcuts/doc/local_doc_resources.go:2348

	decoder := xml.NewDecoder(strings.NewReader(raw))
	for {
		token, err := decoder.Token()
		if err != nil {
			return localDocResourceTag{}, err
		}
		start, ok := token.(xml.StartElement)
		if !ok {
			continue
		}
		if start.Name.Local != expected {
			return localDocResourceTag{}, fmt.Errorf("expected <%s>, got <%s>", expected, start.Name.Local) //nolint:forbidigo // caller wraps with typed validation error.
		}
		attrs := make([]html5BlockAttr, 0, len(start.Attr))
		seenAttrs := make(map[string]struct{}, len(start.Attr))
		for _, attr := range start.Attr {
			attrName := strings.ToLower(strings.TrimSpace(attr.Name.Local))
			if _, exists := seenAttrs[attrName]; exists {
				return localDocResourceTag{}, fmt.Errorf("duplicate attribute %q", attrName) //nolint:forbidigo // caller wraps with typed validation error.
			}
			seenAttrs[attrName] = struct{}{}
			attrs = append(attrs, html5BlockAttr{Name: attr.Name.Local, Value: attr.Value})
		}
		return localDocResourceTag{Name: expected, Attrs: attrs, SelfClosing: strings.HasSuffix(strings.TrimSpace(raw), "/>")}, nil
	}
}

func escapeBareXMLAmpersandsInTagAttr(raw, targetAttr string) string {
	for i := 1; i < len(raw); {
		for i < len(raw) && isXMLSpace(raw[i]) {
			i++
		}
		nameStart := i
		for i < len(raw) && isLocalDocResourceAttrNameByte(raw[i]) {
			i++
		}
		if nameStart == i {

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Remove the duplicated attribute from the tag
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at shortcuts/doc/local_doc_resources.go:2348 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/cc97134529ea6c22. Report an issue: GitHub.