larksuite/cli · error

applying visual styles: %w

Error message

applying visual styles: %w

What it means

After writing cell data, writeSheetData applies visual styles (fills, formats, merges) via applyWorkbookCreateVisualOps. This error wraps any failure of that styling pass. Data rows may already be written; the error is surfaced as a partial_success message string via tablePutPartial rather than a typed final error.

Source

Thrown at shortcuts/sheets/lark_sheet_table_io.go:935

			end = len(matrix)
		}
		batchRange := fmt.Sprintf("%s%d:%s%d", startCol, baseRow+start+1, endCol, baseRow+end)
		input := map[string]interface{}{
			"excel_id": token,
			"sheet_id": sheetID,
			"range":    batchRange,
			"cells":    matrix[start:end],
		}
		if !allowOverwrite {
			input["allow_overwrite"] = false
		}
		if _, err := callTool(ctx, runtime, token, ToolKindWrite, "set_cell_range", input); err != nil {
			return nil, fmt.Errorf("writing rows %d-%d: %w", start+1, end, err) //nolint:forbidigo // intermediate error; surfaced as a partial_success message string via tablePutPartial, not a typed final error
		}
		writes++
	}
	if err := applyWorkbookCreateVisualOps(ctx, runtime, token, sheetID, styles); err != nil {
		return nil, fmt.Errorf("applying visual styles: %w", err) //nolint:forbidigo // intermediate error; surfaced as a partial_success message string via tablePutPartial, not a typed final error
	}
	return map[string]interface{}{
		"name":      s.Name,
		"sheet_id":  sheetID,
		"range":     fmt.Sprintf("%s%d:%s%d", startCol, baseRow+1, endCol, baseRow+len(matrix)),
		"data_rows": len(s.Rows),
		"columns":   writeCols,
		"writes":    writes,
		"mode":      writeModeName(s),
	}, nil
}

// writeModeName normalizes the sheet's write mode to a non-empty label for
// result / dry-run reporting ("" defaults to "overwrite").
func writeModeName(s *tableSheetSpec) string {
	if s.Mode == "append" {
		return "append"
	}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Retry the put; if data was written, only the styling step needs to succeed on retry.
  2. Validate style ranges fall inside the sheet's written grid dimensions.
  3. Reduce the number of style ops per call to avoid rate limits.
  4. Check the token's permission to modify cell styles on the target sheet.

Example fix

// before: style range outside written grid
{"styles": [{"range": "A1:F999", "bg": "#EEE"}]}
// after: keep style ranges within the written matrix
{"styles": [{"range": "A1:F10", "bg": "#EEE"}]}
Defensive patterns

Strategy: retry

Validate before calling

// check style ranges fit inside the written grid:
for _, st := range styles {
	if !withinGrid(st.Range, writtenRows, writtenCols) { return fmt.Errorf("style range %s out of grid", st.Range) }
}

Try / catch

if strings.Contains(err.Error(), "applying visual styles") {
	// data likely written; retry the put or apply styles separately
}

Prevention

When it happens

Trigger: lark sheet table put with style specs (--styles or payload styles) where a style-apply API call fails: invalid style range, unsupported style op, permission or rate-limit rejection from the Lark styling endpoint.

Common situations: Style range strings referencing columns/rows outside the written grid; complex style payloads on sheets with restrictive permissions; transient API errors when applying many style ops in sequence.

Related errors


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