{"record":{"id":"7483ebcb1cb68680","repo":"wavetermdev/waveterm","slug":"getting-absolute-path-w-7483eb","errorCode":null,"errorMessage":"getting absolute path: %w","messagePattern":"getting absolute path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-view.go","lineNumber":78,"sourceCode":"\tfileArg := args[0]\n\tconn := RpcContext.Conn\n\tvar wshCmd *wshrpc.CommandCreateBlockData\n\tif strings.HasPrefix(fileArg, \"http://\") || strings.HasPrefix(fileArg, \"https://\") {\n\t\twshCmd = &wshrpc.CommandCreateBlockData{\n\t\t\tTabId: tabId,\n\t\t\tBlockDef: &waveobj.BlockDef{\n\t\t\t\tMeta: map[string]any{\n\t\t\t\t\twaveobj.MetaKey_View: \"web\",\n\t\t\t\t\twaveobj.MetaKey_Url:  fileArg,\n\t\t\t\t},\n\t\t\t},\n\t\t\tMagnified: viewMagnified,\n\t\t\tFocused:   true,\n\t\t}\n\t} else {\n\t\tabsFile, err := filepath.Abs(fileArg)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"getting absolute path: %w\", err)\n\t\t}\n\t\tabsParent, err := filepath.Abs(filepath.Dir(fileArg))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"getting absolute path of parent dir: %w\", err)\n\t\t}\n\t\t_, err = os.Stat(absParent)\n\t\tif err == fs.ErrNotExist {\n\t\t\treturn fmt.Errorf(\"parent directory does not exist: %q\", absParent)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"getting file info: %w\", err)\n\t\t}\n\t\twshCmd = &wshrpc.CommandCreateBlockData{\n\t\t\tTabId: tabId,\n\t\t\tBlockDef: &waveobj.BlockDef{\n\t\t\t\tMeta: map[string]interface{}{\n\t\t\t\t\twaveobj.MetaKey_View: \"preview\",\n\t\t\t\t\twaveobj.MetaKey_File: absFile,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-view.go#L60-L96","documentation":"For non-URL arguments, viewRun resolves the target to an absolute path with filepath.Abs(fileArg) before constructing the create-block command. filepath.Abs only fails in exotic cases (e.g. working directory cannot be determined on Windows, or pathological input), and when it does the command wraps the error with this message.","triggerScenarios":"Calling `wsh view <file>` when the process's current working directory cannot be resolved by os.Getwd (filepath.Abs depends on it for relative paths) — e.g. the cwd was deleted, or a Windows drive/path resolution failure.","commonSituations":"Running from a directory that was deleted while the shell still sits in it; corrupted cwd state in container/nspawn environments; extremely malformed path arguments on Windows (reserved device names).","solutions":["`cd` to a valid existing directory before running the command","Verify the path string is well-formed for your OS (no NUL bytes/reserved names)","If scripting, resolve the path yourself first and pass an absolute path"],"exampleFix":"// before\n$ cd /tmp/deleted-dir && wsh view notes.md\n\n// after\n$ cd /home/user && wsh view notes.md","handlingStrategy":"validation","validationCode":"# shell\nTARGET=$(readlink -f \"$1\") || exit 1\nwsh view \"$TARGET\"","typeGuard":null,"tryCatchPattern":"try {\n  err := viewRun(cmd, args)\n  if err != nil && strings.Contains(err.Error(), \"getting absolute path\") {\n    // fall back to an absolute path computed in a known-good cwd\n  }\n}","preventionTips":["Keep the shell cwd valid (avoid cd into then deleting dirs)","Pass absolute, well-formed paths when scripting"],"tags":["cli","filesystem","path-resolution"],"backgroundTag":"path-resolution-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}