larksuite/cli · error

segment %q traverses non-object shape

Error message

segment %q traverses non-object shape

What it means

During override/pointer traversal, resolveShapeField was asked to descend into a field whose shape is not an object (and not a oneOf that resolves to objects), so a further path segment cannot be applied. The library refuses to traverse into scalars, arrays, or primitives via JSON Pointer segments.

Source

Thrown at shortcuts/common/typed_compile_contract.go:165

				return field.Shape, nil
			}
		}
		return nil, fmt.Errorf("field %q does not exist", name)
	case typedOneOfShape:
		var resolved []typedValueShape
		for _, variant := range value.Variants {
			if _, null := variant.(typedNullShape); null {
				continue
			}
			field, err := resolveShapeField(variant, name)
			if err != nil {
				return nil, err
			}
			resolved = append(resolved, field)
		}
		return combineResolvedShapes(resolved)
	default:
		return nil, fmt.Errorf("segment %q traverses non-object shape", name)
	}
}

func combineResolvedShapes(shapes []typedValueShape) (typedValueShape, error) {
	switch len(shapes) {
	case 0:
		return nil, fmt.Errorf("shape has no applicable variant")
	case 1:
		return shapes[0], nil
	default:
		return typedOneOfShape{Variants: shapes}, nil
	}
}

func shapeAsObject(shape typedValueShape) (typedObjectShape, bool) {
	if object, ok := shape.(typedObjectShape); ok {
		return object, true
	}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Shorten the Path to stop at the last object-typed field and override that field's whole value instead.
  2. If the target is inside an array element, override the array itself or restructure the data so the target is an object field.
  3. Verify the intermediate field's shape is a struct (typedObjectShape) at that depth.

Example fix

// before
{Path: "/tags/0", Value: "x"} // tags is []string
// after
{Path: "/tags", Value: []string{"x"}}
Defensive patterns

Strategy: type-guard

Validate before calling

// ensure the segment being traversed is a struct-typed field
type dataShape interface{ FieldNames() []string }
func isObjectField(f any) bool { _, ok := f.(dataShape); return ok }

Type guard

func isObjectField(f any) bool {
  _, ok := f.(interface{ FieldNames() []string })
  return ok
}

Prevention

When it happens

Trigger: compileData with an override Path having more segments than the nested depth of objects, e.g. Path "/items/0/name" where 'items' compiles to an array shape, or "/count/x" where 'count' is an int.

Common situations: Assuming JSON Pointer array-index syntax works on typed shapes (it does not here); overriding a field inside a scalar; over-nesting a path after refactoring the struct to a flatter shape.

Related errors


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