{"record":{"id":"cc1b89e829ebe0c3","repo":"larksuite/cli","slug":"adopting-the-default-sheet-as-q-failed-w","errorCode":null,"errorMessage":"adopting the default sheet as %q failed: %w","messagePattern":"adopting the default sheet as %q failed: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/sheets/lark_sheet_table_io.go","lineNumber":1023,"sourceCode":"// writes into an existing workbook, with no default sheet to adopt);\n// +workbook-create passes the default sheet's id.\n//\n// On failure it returns the summaries written so far alongside the error, so\n// the caller can surface a partial_success.\nfunc writeTypedSheets(ctx context.Context, runtime *common.RuntimeContext, token string, payload *tablePayload, adoptSheetID string, styles *workbookCreateSheetStyles) ([]interface{}, error) {\n\tbyName, dimsByName, err := listSheetIDsByName(ctx, runtime, token)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Adopt the default sheet as the first payload sheet (rename + reuse), so a\n\t// just-created workbook doesn't keep its empty default sheet around. Skip if\n\t// a sheet by that name already exists (it'll be matched normally below).\n\tif adoptSheetID != \"\" && len(payload.Sheets) > 0 {\n\t\tfirst := payload.Sheets[0].Name\n\t\tif _, exists := byName[first]; !exists {\n\t\t\tif err := renameSheet(ctx, runtime, token, adoptSheetID, first); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"adopting the default sheet as %q failed: %w\", first, err) //nolint:forbidigo // intermediate error; surfaced as a partial_success message string via tablePutPartial, not a typed final error\n\t\t\t}\n\t\t\t// The adopted sheet's OLD name must stop resolving: a later payload\n\t\t\t// sheet named \"Sheet1\" would otherwise match the stale entry and\n\t\t\t// silently overwrite the first sheet's data (live-verified: a\n\t\t\t// [Sales, Sheet1] payload wrote both into one sheet, destroying\n\t\t\t// Sales, while reporting both as written). Its grid dims move to\n\t\t\t// the new name so append-mode's lastDataRow probe keeps its\n\t\t\t// full-grid anchor.\n\t\t\tfor name, id := range byName {\n\t\t\t\tif id == adoptSheetID && name != first {\n\t\t\t\t\tdelete(byName, name)\n\t\t\t\t\tif d, ok := dimsByName[name]; ok {\n\t\t\t\t\t\tdimsByName[first] = d\n\t\t\t\t\t\tdelete(dimsByName, name)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbyName[first] = adoptSheetID","sourceCodeStart":1005,"sourceCodeEnd":1041,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/sheets/lark_sheet_table_io.go#L1005-L1041","documentation":"When a new workbook is created, table put tries to adopt its empty default sheet by renaming it to the first payload sheet's name instead of leaving a stray empty sheet. This error wraps a renameSheet failure during that adoption. It is surfaced as a partial_success message string via tablePutPartial; the workbook exists but its sheets may be partially set up.","triggerScenarios":"Creating a brand-new workbook via table put where the rename of the default sheet (e.g. 'Sheet1') to the first payload sheet name fails — typically a permission/API rejection on modify_workbook_structure, or a name constraint violation.","commonSituations":"Token lacking write permission on the just-created workbook; sheet name colliding with backend constraints (length, forbidden characters); transient API failure right after workbook creation.","solutions":["Retry the table put; a fresh workbook creation plus rename is usually idempotent-safe on retry.","Simplify the first sheet's name (ASCII, shorter, no special characters) and retry.","Verify the credential can modify workbooks in the target folder/domain.","Use an existing spreadsheet token instead of creating a new one to skip the adoption path."],"exampleFix":"// before: name that trips backend constraints\n{\"sheets\": [{\"name\": \"Q4 / P&L (final)!!\", \"rows\": [[\"a\"]]}\"]}\n// after\n{\"sheets\": [{\"name\": \"Q4 PnL Final\", \"rows\": [[\"a\"]]}]}","handlingStrategy":"retry","validationCode":"// pre-validate the first sheet name for backend constraints:\nif len(firstSheetName) == 0 || len(firstSheetName) > 100 || strings.ContainsAny(firstSheetName, \"/\\\\?*[ ]:\") {\n\treturn fmt.Errorf(\"sheet name %q may be rejected\", firstSheetName)\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"adopting the default sheet\") {\n\t// inspect workbook state (which sheets exist) before retrying the put\n}","preventionTips":["Prefer putting into an existing spreadsheet token over creating new ones.","Keep sheet names simple ASCII without special characters.","Check workbook state after a failed create before retrying."],"tags":["sheets","workbook-creation","rename"],"backgroundTag":"sheet-rename-failed","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"}