{"record":{"id":"d23b3f2c9d9bb924","repo":"wavetermdev/waveterm","slug":"error-creating-block-w","errorCode":null,"errorMessage":"error creating block: %w","messagePattern":"error creating block: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wcore/block.go","lineNumber":86,"sourceCode":"\tdefer func() {\n\t\tif rtnErr == nil {\n\t\t\treturn\n\t\t}\n\t\t// if there was an error, and we created the block, clean it up since the function failed\n\t\tif blockCreated && newBlockOID != \"\" {\n\t\t\tdeleteBlockObj(ctx, newBlockOID)\n\t\t\tfilestore.WFS.DeleteZone(ctx, newBlockOID)\n\t\t}\n\t}()\n\tif blockDef == nil {\n\t\treturn nil, fmt.Errorf(\"blockDef is nil\")\n\t}\n\tif blockDef.Meta == nil || blockDef.Meta.GetString(waveobj.MetaKey_View, \"\") == \"\" {\n\t\treturn nil, fmt.Errorf(\"no view provided for new block\")\n\t}\n\tblockData, err := createBlockObj(ctx, tabId, blockDef, rtOpts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating block: %w\", err)\n\t}\n\tblockCreated = true\n\tnewBlockOID = blockData.OID\n\t// upload the files if present\n\tif len(blockDef.Files) > 0 {\n\t\tfor fileName, fileDef := range blockDef.Files {\n\t\t\terr := filestore.WFS.MakeFile(ctx, newBlockOID, fileName, fileDef.Meta, wshrpc.FileOpts{})\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error making blockfile %q: %w\", fileName, err)\n\t\t\t}\n\t\t\terr = filestore.WFS.WriteFile(ctx, newBlockOID, fileName, []byte(fileDef.Content))\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error writing blockfile %q: %w\", fileName, err)\n\t\t\t}\n\t\t}\n\t}\n\tif recordTelemetry {\n\t\tblockView := blockDef.Meta.GetString(waveobj.MetaKey_View, \"\")","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wcore/block.go#L68-L104","documentation":"This wraps failures from createBlockObj, which persists the new Block object under the given tab in a store transaction. The %w-wrapped inner error carries the actual reason (tab missing, DB failure, etc.).","triggerScenarios":"CreateBlockWithTelemetry called with valid blockDef but createBlockObj fails: nonexistent tabId, database/transaction error, or invalid runtime options.","commonSituations":"Creating a block against a tab that was just closed; SQLite lock or corruption; invalid RtOpts values rejected during persistence.","solutions":["Read the wrapped inner error for the root cause","Verify tabId refers to an existing tab (re-fetch if the UI may have closed it)","Retry after fixing DB-level issues (locks, disk space)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"tab, _ := wstore.DBGet[*waveobj.Tab](ctx, tabId)\nif tab == nil { return errors.New(\"tab missing, aborting block creation\") }","typeGuard":null,"tryCatchPattern":"block, err := wcore.CreateBlock(ctx, tabId, blockDef, rtOpts)\nif err != nil {\n    if strings.Contains(err.Error(), \"error creating block\") {\n        // unwrap/log inner cause, optionally retry\n    }\n}","preventionTips":["Verify the tab exists immediately before creating blocks","Unwrap errors with errors.Is/As for the root cause","Watch for DB lock/contention in concurrent block creation"],"tags":["database","blocks","wrapped-error"],"backgroundTag":"wrapped-root-cause-error","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}