Skip to content

Commit 8aef06c

Browse files
committed
add error handling and fix workspace directory fetch
- add try/catch to folder browse dialog in workspace editor - refactor getWorkspaceDirectory to getWorkspaceInfo returning both wsId and wsDir - fetch workspace info once with timeout and pass to makeSwapToken to avoid duplicate DB calls
1 parent 678f79d commit 8aef06c

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

frontend/app/tab/workspaceeditor.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,13 @@ export const WorkspaceEditor = memo(function WorkspaceEditor({
132132
<Button
133133
className="ghost browse-btn"
134134
onClick={async () => {
135-
const path = await getApi().showOpenFolderDialog();
136-
if (path) {
137-
onDirectoryChange(path);
135+
try {
136+
const path = await getApi().showOpenFolderDialog();
137+
if (path) {
138+
onDirectoryChange(path);
139+
}
140+
} catch (e) {
141+
console.error("error opening folder dialog:", e);
138142
}
139143
}}
140144
>

pkg/blockcontroller/shellcontroller.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,15 @@ func (bc *ShellController) setupAndStartShellProcess(logCtx context.Context, rc
386386
blocklogger.Infof(logCtx, "[conndebug] remoteName: %q, connType: %s, wshEnabled: %v, shell: %q, shellType: %s\n", remoteName, connUnion.ConnType, connUnion.WshEnabled, connUnion.ShellPath, connUnion.ShellType)
387387
var cmdStr string
388388
var cmdOpts shellexec.CommandOptsType
389+
wsCtx, wsCancel := context.WithTimeout(context.Background(), 2*time.Second)
390+
wsId, wsDir := getWorkspaceInfo(wsCtx, bc.TabId)
391+
wsCancel()
389392
if bc.ControllerType == BlockController_Shell {
390393
cmdOpts.Interactive = true
391394
cmdOpts.Login = true
392395
cmdOpts.Cwd = blockMeta.GetString(waveobj.MetaKey_CmdCwd, "")
393396
if cmdOpts.Cwd == "" && connUnion.ConnType == ConnType_Local {
394-
cmdOpts.Cwd = getWorkspaceDirectory(ctx, bc.TabId)
397+
cmdOpts.Cwd = wsDir
395398
}
396399
if cmdOpts.Cwd != "" {
397400
cwdPath, err := wavebase.ExpandHomeDir(cmdOpts.Cwd)
@@ -411,7 +414,7 @@ func (bc *ShellController) setupAndStartShellProcess(logCtx context.Context, rc
411414
return nil, fmt.Errorf("unknown controller type %q", bc.ControllerType)
412415
}
413416
var shellProc *shellexec.ShellProc
414-
swapToken := bc.makeSwapToken(ctx, logCtx, blockMeta, remoteName, connUnion.ShellType)
417+
swapToken := bc.makeSwapToken(ctx, logCtx, blockMeta, remoteName, connUnion.ShellType, wsId, wsDir)
415418
cmdOpts.SwapToken = swapToken
416419
blocklogger.Debugf(logCtx, "[conndebug] created swaptoken: %s\n", swapToken.Token)
417420
if connUnion.ConnType == ConnType_Wsl {
@@ -718,22 +721,22 @@ func createCmdStrAndOpts(blockId string, blockMeta waveobj.MetaMapType, connName
718721
return cmdStr, &cmdOpts, nil
719722
}
720723

721-
func getWorkspaceDirectory(ctx context.Context, tabId string) string {
724+
func getWorkspaceInfo(ctx context.Context, tabId string) (wsId string, wsDir string) {
722725
if tabId == "" {
723-
return ""
726+
return "", ""
724727
}
725728
wsId, err := wstore.DBFindWorkspaceForTabId(ctx, tabId)
726729
if err != nil {
727-
return ""
730+
return "", ""
728731
}
729732
ws, err := wstore.DBGet[*waveobj.Workspace](ctx, wsId)
730733
if err != nil || ws == nil {
731-
return ""
734+
return wsId, ""
732735
}
733-
return ws.Directory
736+
return wsId, ws.Directory
734737
}
735738

736-
func (bc *ShellController) makeSwapToken(ctx context.Context, logCtx context.Context, blockMeta waveobj.MetaMapType, remoteName string, shellType string) *shellutil.TokenSwapEntry {
739+
func (bc *ShellController) makeSwapToken(ctx context.Context, logCtx context.Context, blockMeta waveobj.MetaMapType, remoteName string, shellType string, wsId string, wsDir string) *shellutil.TokenSwapEntry {
737740
token := &shellutil.TokenSwapEntry{
738741
Token: uuid.New().String(),
739742
Env: make(map[string]string),
@@ -749,17 +752,11 @@ func (bc *ShellController) makeSwapToken(ctx context.Context, logCtx context.Con
749752
} else {
750753
token.Env["WAVETERM_TABID"] = tabId
751754
}
752-
if tabId != "" {
753-
wsId, err := wstore.DBFindWorkspaceForTabId(ctx, tabId)
754-
if err != nil {
755-
log.Printf("error finding workspace for tab: %v\n", err)
756-
} else {
757-
token.Env["WAVETERM_WORKSPACEID"] = wsId
758-
ws, err := wstore.DBGet[*waveobj.Workspace](ctx, wsId)
759-
if err == nil && ws != nil && ws.Directory != "" {
760-
token.Env["WAVETERM_WORKSPACE_DIR"] = ws.Directory
761-
}
762-
}
755+
if wsId != "" {
756+
token.Env["WAVETERM_WORKSPACEID"] = wsId
757+
}
758+
if wsDir != "" {
759+
token.Env["WAVETERM_WORKSPACE_DIR"] = wsDir
763760
}
764761
clientData, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
765762
if err != nil {

0 commit comments

Comments
 (0)