{"record":{"id":"7502f9c6124caf82","repo":"wavetermdev/waveterm","slug":"error-parsing-connection-s-w","errorCode":null,"errorMessage":"error parsing connection %s: %w","messagePattern":"error parsing connection (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/remote/fileshare/wshfs/wshfs.go","lineNumber":38,"sourceCode":"\nconst (\n\tRemoteFileTransferSizeLimit = 32 * 1024 * 1024\n\tDefaultTimeout              = 30 * time.Second\n\tFileMode                    = os.FileMode(0644)\n\tDirMode                     = os.FileMode(0755) | os.ModeDir\n\tRecursiveRequiredError      = \"recursive flag must be set for directory operations\"\n\tMergeRequiredError          = \"directory already exists at %q, set overwrite flag to delete the existing contents or set merge flag to merge the contents\"\n\tOverwriteRequiredError      = \"file already exists at %q, set overwrite flag to delete the existing file\"\n)\n\n// This needs to be set by whoever initializes the client, either main-server or wshcmd-connserver\nvar RpcClient *wshutil.WshRpc\nvar RpcClientRouteId string\n\nfunc parseConnection(ctx context.Context, path string) (*connparse.Connection, error) {\n\tconn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing connection %s: %w\", path, err)\n\t}\n\treturn conn, nil\n}\n\nfunc Read(ctx context.Context, data wshrpc.FileData) (*wshrpc.FileData, error) {\n\tif data.Info == nil {\n\t\treturn nil, fmt.Errorf(\"file info is required\")\n\t}\n\tlog.Printf(\"Read: %v\", data.Info.Path)\n\tconn, err := parseConnection(ctx, data.Info.Path)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tbroker := RpcClient.StreamBroker\n\tif broker == nil {\n\t\treturn nil, fmt.Errorf(\"stream broker not available\")\n\t}\n\tif RpcClientRouteId == \"\" {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/remote/fileshare/wshfs/wshfs.go#L20-L56","documentation":"This error is returned by parseConnection when connparse.ParseURIAndReplaceCurrentHost fails to parse the given path as a valid connection URI (wshfs uses connection URIs like \"wsh://host/path\" or local paths). It wraps the underlying parse error with the offending path so the caller knows which input was rejected. All wshfs file operations (Read, Stat, ListEntries, Move, etc.) parse their path argument first, so any operation with a malformed URI surfaces this error.","triggerScenarios":"Calling wshfs.Read, Stat, ListEntries, ListEntriesStream, GetConnectionRouteId, FileStream, PutFile, Append, Mkdir, Move, or Copy with a path string that connparse cannot parse — e.g. an empty string, a malformed scheme like \"://host/path\", or an otherwise invalid connection URI.","commonSituations":"Users pass plain relative paths that lack a host component in a context requiring a full URI; paths were built by string concatenation with missing or duplicated scheme; a config value (e.g. a remote host alias) is empty or contains invalid characters; UI passes an unresolved placeholder like \"{{host}}\".","solutions":["Log/inspect the full wrapped error to see which path failed and the underlying connparse reason","Validate the path is a well-formed connection URI (non-empty, valid scheme) before calling the wshfs API","If operating on the local machine, ensure the path is an absolute local path or uses the proper local connection URI form","Fix the source of the path (config, env var, CLI arg) so it no longer contains invalid characters or empty segments"],"exampleFix":"// before\nwshfs.Read(ctx, wshrpc.FileData{Info: &wshrpc.FileInfo{Path: \"://bad uri\"}})\n// after\npath := \"wsh://myhost/home/user/file.txt\" // well-formed connection URI\nwshfs.Read(ctx, wshrpc.FileData{Info: &wshrpc.FileInfo{Path: path}})","handlingStrategy":"validation","validationCode":"func validConnURI(p string) bool {\n    return p != \"\" && (strings.Contains(p, \"://\") || filepath.IsAbs(p))\n}\nif !validConnURI(path) {\n    return fmt.Errorf(\"invalid connection uri: %q\", path)\n}","typeGuard":"func hasConnScheme(p string) bool {\n    u, err := url.Parse(p)\n    return err == nil && u.Scheme != \"\" && u.Host != \"\"\n}","tryCatchPattern":"conn, err := wshfs.Stat(ctx, path)\nif err != nil {\n    var parseErr *fmt.wrapError\n    if errors.As(err, &parseErr) && strings.Contains(err.Error(), \"error parsing connection\") {\n        return fmt.Errorf(\"malformed path %q: %w\", path, err)\n    }\n    return err\n}","preventionTips":["Validate paths/schemes at the boundary (CLI args, config load) before calling wshfs","Never build URIs by raw string concatenation; use a helper that formats scheme+host+path","Log the offending path from the wrapped error to catch bad producers early","Add unit tests covering empty and malformed paths"],"tags":["go","uri-parsing","connection"],"backgroundTag":"invalid-connection-uri","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}