Skip to content

Commit 4f6aa38

Browse files
authored
fix issue when tab does not exist in workspace (#2580)
this fixes a rare case where a workspace tries to load a tab that doesn't exist. this allows the UI to load even despite that condition. in addition it fixes the "delete tab" path so, even if the tab doesn't exist, it will get cleaned up correctly out of the workspace.
1 parent 6df961c commit 4f6aa38

File tree

6 files changed

+40
-34
lines changed

6 files changed

+40
-34
lines changed

frontend/wave.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,23 @@ async function initWave(initOpts: WaveInitOpts) {
181181
subscribeToConnEvents();
182182

183183
// ensures client/window/workspace are loaded into the cache before rendering
184-
const [client, waveWindow, initialTab] = await Promise.all([
185-
WOS.loadAndPinWaveObject<Client>(WOS.makeORef("client", initOpts.clientId)),
186-
WOS.loadAndPinWaveObject<WaveWindow>(WOS.makeORef("window", initOpts.windowId)),
187-
WOS.loadAndPinWaveObject<Tab>(WOS.makeORef("tab", initOpts.tabId)),
188-
]);
189-
const [ws, layoutState] = await Promise.all([
190-
WOS.loadAndPinWaveObject<Workspace>(WOS.makeORef("workspace", waveWindow.workspaceid)),
191-
WOS.reloadWaveObject<LayoutState>(WOS.makeORef("layout", initialTab.layoutstate)),
192-
]);
193-
loadAllWorkspaceTabs(ws);
194-
WOS.wpsSubscribeToObject(WOS.makeORef("workspace", waveWindow.workspaceid));
195-
196-
document.title = `Wave Terminal - ${initialTab.name}`; // TODO update with tab name change
197-
184+
try {
185+
const [client, waveWindow, initialTab] = await Promise.all([
186+
WOS.loadAndPinWaveObject<Client>(WOS.makeORef("client", initOpts.clientId)),
187+
WOS.loadAndPinWaveObject<WaveWindow>(WOS.makeORef("window", initOpts.windowId)),
188+
WOS.loadAndPinWaveObject<Tab>(WOS.makeORef("tab", initOpts.tabId)),
189+
]);
190+
const [ws, layoutState] = await Promise.all([
191+
WOS.loadAndPinWaveObject<Workspace>(WOS.makeORef("workspace", waveWindow.workspaceid)),
192+
WOS.reloadWaveObject<LayoutState>(WOS.makeORef("layout", initialTab.layoutstate)),
193+
]);
194+
loadAllWorkspaceTabs(ws);
195+
WOS.wpsSubscribeToObject(WOS.makeORef("workspace", waveWindow.workspaceid));
196+
document.title = `Wave Terminal - ${initialTab.name}`; // TODO update with tab name change
197+
} catch (e) {
198+
console.error("Failed initialization error", e);
199+
getApi().sendLog("Error in initialization (wave.ts, loading required objects) " + e.message + "\n" + e.stack);
200+
}
198201
registerGlobalKeys();
199202
registerElectronReinjectKeyHandler();
200203
registerControlShiftStateUpdateHandler();

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ require (
3333
github.com/spf13/cobra v1.10.1
3434
github.com/ubuntu/gowsl v0.0.0-20240906163211-049fd49bd93b
3535
github.com/wavetermdev/htmltoken v0.2.0
36-
github.com/wavetermdev/waveterm/tsunami v0.0.0-00010101000000-000000000000
36+
github.com/wavetermdev/waveterm/tsunami v0.12.3
3737
golang.org/x/crypto v0.45.0
3838
golang.org/x/mod v0.30.0
3939
golang.org/x/sync v0.18.0
@@ -80,6 +80,7 @@ require (
8080
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
8181
github.com/mailru/easyjson v0.7.7 // indirect
8282
github.com/mattn/go-isatty v0.0.20 // indirect
83+
github.com/outrigdev/goid v0.3.0 // indirect
8384
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
8485
github.com/rivo/uniseg v0.4.7 // indirect
8586
github.com/sirupsen/logrus v1.9.3 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuE
144144
github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
145145
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
146146
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
147+
github.com/outrigdev/goid v0.3.0 h1:t/otQD3EXc45cLtQVPUnNgEyRaTQA4cPeu3qVcrsIws=
148+
github.com/outrigdev/goid v0.3.0/go.mod h1:hEH7f27ypN/GHWt/7gvkRoFYR0LZizfUBIAbak4neVE=
147149
github.com/photostorm/pty v1.1.19-0.20230903182454-31354506054b h1:cLGKfKb1uk0hxI0Q8L83UAJPpeJ+gSpn3cCU/tjd3eg=
148150
github.com/photostorm/pty v1.1.19-0.20230903182454-31354506054b/go.mod h1:KO+FcPtyLAiRC0hJwreJVvfwc7vnNz77UxBTIGHdPVk=
149151
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=

pkg/service/workspaceservice/workspaceservice.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,14 @@ func (svc *WorkspaceService) CloseTab_Meta() tsgenmeta.MethodMeta {
259259
// returns the new active tabid
260260
func (svc *WorkspaceService) CloseTab(ctx context.Context, workspaceId string, tabId string, fromElectron bool) (*CloseTabRtnType, waveobj.UpdatesRtnType, error) {
261261
ctx = waveobj.ContextWithUpdates(ctx)
262-
tab, err := wstore.DBMustGet[*waveobj.Tab](ctx, tabId)
263-
if err != nil {
264-
return nil, nil, fmt.Errorf("error getting tab: %w", err)
262+
tab, err := wstore.DBGet[*waveobj.Tab](ctx, tabId)
263+
if err == nil && tab != nil {
264+
go func() {
265+
for _, blockId := range tab.BlockIds {
266+
blockcontroller.StopBlockController(blockId)
267+
}
268+
}()
265269
}
266-
go func() {
267-
for _, blockId := range tab.BlockIds {
268-
blockcontroller.StopBlockController(blockId)
269-
}
270-
}()
271270
newActiveTabId, err := wcore.DeleteTab(ctx, workspaceId, tabId, true)
272271
if err != nil {
273272
return nil, nil, fmt.Errorf("error closing tab: %w", err)

pkg/wcore/block.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func createBlockObj(ctx context.Context, tabId string, blockDef *waveobj.BlockDe
150150
// recursive: if true, will recursively close parent tab, window, workspace, if they are empty.
151151
// Returns new active tab id, error.
152152
func DeleteBlock(ctx context.Context, blockId string, recursive bool) error {
153-
block, err := wstore.DBMustGet[*waveobj.Block](ctx, blockId)
153+
block, err := wstore.DBGet[*waveobj.Block](ctx, blockId)
154154
if err != nil {
155155
return fmt.Errorf("error getting block: %w", err)
156156
}
@@ -223,11 +223,11 @@ func deleteBlockObj(ctx context.Context, blockId string) (int, error) {
223223
}
224224
}
225225
wstore.DBDelete(tx.Context(), waveobj.OType_Block, blockId)
226-
226+
227227
// Clean up block runtime info
228228
blockORef := waveobj.MakeORef(waveobj.OType_Block, blockId)
229229
wstore.DeleteRTInfo(blockORef)
230-
230+
231231
return parentBlockCount, nil
232232
})
233233
}

pkg/wcore/workspace.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,12 @@ func DeleteTab(ctx context.Context, workspaceId string, tabId string, recursive
290290

291291
// close blocks (sends events + stops block controllers)
292292
tab, _ := wstore.DBGet[*waveobj.Tab](ctx, tabId)
293-
if tab == nil {
294-
return "", fmt.Errorf("tab not found: %q", tabId)
295-
}
296-
for _, blockId := range tab.BlockIds {
297-
err := DeleteBlock(ctx, blockId, false)
298-
if err != nil {
299-
return "", fmt.Errorf("error deleting block %s: %w", blockId, err)
293+
if tab != nil {
294+
for _, blockId := range tab.BlockIds {
295+
err := DeleteBlock(ctx, blockId, false)
296+
if err != nil {
297+
return "", fmt.Errorf("error deleting block %s: %w", blockId, err)
298+
}
300299
}
301300
}
302301

@@ -319,7 +318,9 @@ func DeleteTab(ctx context.Context, workspaceId string, tabId string, recursive
319318

320319
wstore.DBUpdate(ctx, ws)
321320
wstore.DBDelete(ctx, waveobj.OType_Tab, tabId)
322-
wstore.DBDelete(ctx, waveobj.OType_LayoutState, tab.LayoutState)
321+
if tab != nil {
322+
wstore.DBDelete(ctx, waveobj.OType_LayoutState, tab.LayoutState)
323+
}
323324

324325
// if no tabs remaining, close window
325326
if recursive && newActiveTabId == "" {

0 commit comments

Comments
 (0)