wavetermdev/waveterm · error

error parsing connection %s: %w

Error message

error parsing connection %s: %w

What it means

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.

Source

Thrown at pkg/remote/fileshare/wshfs/wshfs.go:38

const (
	RemoteFileTransferSizeLimit = 32 * 1024 * 1024
	DefaultTimeout              = 30 * time.Second
	FileMode                    = os.FileMode(0644)
	DirMode                     = os.FileMode(0755) | os.ModeDir
	RecursiveRequiredError      = "recursive flag must be set for directory operations"
	MergeRequiredError          = "directory already exists at %q, set overwrite flag to delete the existing contents or set merge flag to merge the contents"
	OverwriteRequiredError      = "file already exists at %q, set overwrite flag to delete the existing file"
)

// This needs to be set by whoever initializes the client, either main-server or wshcmd-connserver
var RpcClient *wshutil.WshRpc
var RpcClientRouteId string

func parseConnection(ctx context.Context, path string) (*connparse.Connection, error) {
	conn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, path)
	if err != nil {
		return nil, fmt.Errorf("error parsing connection %s: %w", path, err)
	}
	return conn, nil
}

func Read(ctx context.Context, data wshrpc.FileData) (*wshrpc.FileData, error) {
	if data.Info == nil {
		return nil, fmt.Errorf("file info is required")
	}
	log.Printf("Read: %v", data.Info.Path)
	conn, err := parseConnection(ctx, data.Info.Path)
	if err != nil {
		return nil, err
	}
	broker := RpcClient.StreamBroker
	if broker == nil {
		return nil, fmt.Errorf("stream broker not available")
	}
	if RpcClientRouteId == "" {

View on GitHub (pinned to a4447c1563)

Solutions

  1. Log/inspect the full wrapped error to see which path failed and the underlying connparse reason
  2. Validate the path is a well-formed connection URI (non-empty, valid scheme) before calling the wshfs API
  3. If operating on the local machine, ensure the path is an absolute local path or uses the proper local connection URI form
  4. Fix the source of the path (config, env var, CLI arg) so it no longer contains invalid characters or empty segments

Example fix

// before
wshfs.Read(ctx, wshrpc.FileData{Info: &wshrpc.FileInfo{Path: "://bad uri"}})
// after
path := "wsh://myhost/home/user/file.txt" // well-formed connection URI
wshfs.Read(ctx, wshrpc.FileData{Info: &wshrpc.FileInfo{Path: path}})
Defensive patterns

Strategy: validation

Validate before calling

func validConnURI(p string) bool {
    return p != "" && (strings.Contains(p, "://") || filepath.IsAbs(p))
}
if !validConnURI(path) {
    return fmt.Errorf("invalid connection uri: %q", path)
}

Type guard

func hasConnScheme(p string) bool {
    u, err := url.Parse(p)
    return err == nil && u.Scheme != "" && u.Host != ""
}

Try / catch

conn, err := wshfs.Stat(ctx, path)
if err != nil {
    var parseErr *fmt.wrapError
    if errors.As(err, &parseErr) && strings.Contains(err.Error(), "error parsing connection") {
        return fmt.Errorf("malformed path %q: %w", path, err)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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}}".

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/7502f9c6124caf82. Report an issue: GitHub.