chenhg5/cc-connect · error

empty path

Error message

empty path

What it means

After resolving the absolute path, renderReferenceView requires a non-empty filesystem path on the reference. If both pathAbs and pathOriginal are empty, there is no target to stat or render, so it fails fast with 'empty path'.

Source

Thrown at core/reference_show.go:72

	case ref.locationFormat != referenceLocationNone:
		req.Mode = referenceViewContext
	default:
		req.Mode = referenceViewFileHead
		req.MaxLines = defaultShowHeadLines
	}
	return req, nil
}

func renderReferenceView(req *referenceViewRequest) (string, error) {
	if req == nil || req.Ref == nil {
		return "", fmt.Errorf("nil view request")
	}
	path := req.Ref.pathAbs
	if path == "" {
		path = req.Ref.pathOriginal
	}
	if path == "" {
		return "", fmt.Errorf("empty path")
	}
	info, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			return "", fmt.Errorf("path does not exist")
		}
		return "", err
	}
	if info.IsDir() {
		if req.Ref.locationFormat != referenceLocationNone {
			return "", fmt.Errorf("directory reference cannot carry a location")
		}
		return renderReferenceDir(path, req)
	}
	return renderReferenceFile(path, req)
}

func renderReferenceFile(path string, req *referenceViewRequest) (string, error) {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Ensure the reference parser always sets pathAbs (or at least pathOriginal) before the request reaches renderReferenceView
  2. Validate the reference input at parse time and reject empty paths earlier with a clearer message
  3. In tests, set pathOriginal or pathAbs on the Ref

Example fix

// before
ref := &reference{locationFormat: referenceLocationLine}
// after
ref := &reference{pathOriginal: "main.go", pathAbs: "/repo/main.go", locationFormat: referenceLocationLine}
Defensive patterns

Strategy: validation

Validate before calling

if ref.pathAbs == "" && ref.pathOriginal == "" {
    return "", fmt.Errorf("reference has no path")
}

Type guard

func hasPath(r *reference) bool { return r != nil && (r.pathAbs != "" || r.pathOriginal != "") }

Try / catch

out, err := renderReferenceView(req)
if err != nil && strings.Contains(err.Error(), "empty path") {
    return "", fmt.Errorf("show: reference missing a file path")
}

Prevention

When it happens

Trigger: A referenceViewRequest whose Ref has both pathAbs and pathOriginal set to "" — typically a reference created without any path field populated.

Common situations: Parsing logic that assigns the location but not the path; config where the reference string lacks the path component; tests constructing a Ref literal without path fields.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/dadf906da8ec11b4. Report an issue: GitHub.