{"record":{"id":"16ad37e0f9249569","repo":"larksuite/cli","slug":"resolving-last-data-row-for-append-w","errorCode":null,"errorMessage":"resolving last data row for append: %w","messagePattern":"resolving last data row for append: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/sheets/lark_sheet_table_io.go","lineNumber":867,"sourceCode":"\n// writeSheetData writes one sheet's matrix via set_cell_range, splitting into\n// row batches when the cell count would exceed tablePutMaxCellsPerWrite.\n// Returns a per-sheet summary for the result envelope.\nfunc writeSheetData(ctx context.Context, runtime *common.RuntimeContext, token, sheetID string, s *tableSheetSpec, styles *workbookCreateStylePayload, dims gridDims) (map[string]interface{}, error) {\n\t_, col0, row0, err := sheetAnchor(s)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tncols := len(s.Columns)\n\n\t// append mode starts below the sheet's existing data; start_cell's row is\n\t// ignored (its column is still honored). overwrite mode anchors at row0.\n\tbaseRow := row0\n\twriteHeader := headerOn(s)\n\tif s.Mode == \"append\" {\n\t\tlastRow, err := lastDataRow(ctx, runtime, token, sheetID, dims)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"resolving last data row for append: %w\", err) //nolint:forbidigo // intermediate error; surfaced as a partial_success message string via tablePutPartial, not a typed final error\n\t\t}\n\t\tif lastRow > 0 {\n\t\t\tbaseRow = lastRow // 0-based index of the row just below the 1-based last data row\n\t\t} else if s.Header == nil {\n\t\t\t// appending to an empty sheet with no explicit header choice: write the\n\t\t\t// header so column names aren't lost (and a later +table-get doesn't\n\t\t\t// consume the first data row as the header).\n\t\t\twriteHeader = true\n\t\t}\n\t}\n\n\tmatrix, err := buildSheetMatrix(s, writeHeader)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tmatrix, err = applyWorkbookCreateStylesToMatrix(matrix, styles, col0, baseRow, fmt.Sprintf(\"--styles for sheet %q\", s.Name))\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":849,"sourceCodeEnd":885,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/sheets/lark_sheet_table_io.go#L849-L885","documentation":"During a sheet table put in append mode, writeSheetData must first resolve the current last data row of the target sheet to know where to anchor the appended rows. This error wraps any failure of lastDataRow (reading sheet dims/values) so the append cannot proceed. It is surfaced as a partial_success message string via tablePutPartial, not a typed final error.","triggerScenarios":"Running lark sheet table put with mode=append when the API call that reads the sheet's dimensions or existing values fails (network error, permission error, or sheet/token not found) inside lastDataRow.","commonSituations":"Expired or insufficient token scopes for reading the sheet; a spreadsheet_token typo; the sheet was deleted between listing and writing; transient network failures against the Lark gateway.","solutions":["Retry the put; lastDataRow failures are often transient network or rate-limit issues.","Verify the spreadsheet token and sheet ID/name resolve with a read command (e.g. table get).","Check the token has spreadsheet read+write scopes for the target sheet.","Confirm the sheet still exists and wasn't removed by a concurrent edit."],"exampleFix":"// before (ambiguous name, read fails)\nlark sheet table put --token 123 --sheet \"Sumary\" --mode append --header A,B --row 1,2\n// after (verify exact sheet name exists first)\nlark sheet table get --token 123 --sheet \"Summary\"   # confirm readable, then append","handlingStrategy":"retry","validationCode":"// verify the target is readable before appending:\n_, err := runCLI(\"lark\", \"sheet\", \"table\", \"get\", \"--token\", token, \"--sheet\", sheet)\nif err != nil { /* resolve access before attempting append */ }","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"resolving last data row for append\") {\n\t// inspect partial_success message; backoff and retry the append\n}","preventionTips":["Pre-read the sheet with table get to confirm access and existence.","Use tokens with both read and write spreadsheet scopes.","Retry appends with exponential backoff on transient failures."],"tags":["sheets","append","api-error"],"backgroundTag":"sheet-append-anchor-failure","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}