chenhg5/cc-connect · error

empty reference

Error message

empty reference

What it means

`parseUserLocalReference` first trims the raw input and rejects it outright with `empty reference` if nothing remains. This guards the reference-view feature from being invoked with no file path at all, before any pattern matching is attempted.

Source

Thrown at core/reference_parse.go:55

	isRelative     bool
	locationFormat referenceLocationFormat
	lineStart      int
	lineEnd        int
	column         int
}

var (
	reMarkdownLink   = regexp.MustCompile(`\[([^\]]+)\]\(([^)\s]+)\)((?::\d+(?::\d+)?|:\d+-\d+)?)?`)
	reHashLocation   = regexp.MustCompile(`^(.*?)(#L(\d+)(?:C(\d+))?)$`)
	reColonLineCol   = regexp.MustCompile(`^(.*):(\d+):(\d+)$`)
	reColonLineRange = regexp.MustCompile(`^(.*):(\d+)-(\d+)$`)
	reColonLineOnly  = regexp.MustCompile(`^(.*):(\d+)$`)
)

func parseUserLocalReference(raw, workspaceDir string) (*localReference, error) {
	raw = strings.TrimSpace(raw)
	if raw == "" {
		return nil, fmt.Errorf("empty reference")
	}
	if match := reMarkdownLink.FindStringSubmatch(raw); len(match) >= 3 && match[0] == raw {
		suffix := ""
		if len(match) >= 4 {
			suffix = match[3]
		}
		raw = match[2] + suffix
	}
	ref, ok := parseLocalReference(raw, workspaceDir)
	if !ok {
		return nil, fmt.Errorf("cannot parse local reference")
	}
	return ref, nil
}

func parseLocalReference(raw, workspaceDir string) (*localReference, bool) {
	raw = strings.TrimSpace(raw)
	if raw == "" || isWebURL(raw) || strings.HasPrefix(raw, "//") {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check the user-facing command invocation includes a path argument (`/show src/main.go`, not bare `/show`).
  2. Validate/trim the reference in the caller and return a usage hint to the user before calling buildReferenceViewRequest.
  3. Fix the card/button template if it produces an empty path value.
  4. Guard the call site: `if strings.TrimSpace(rawRef) == "" { reply usage; return }`.

Example fix

// before
req, err := buildReferenceViewRequest(arg, workspaceDir)

// after
arg = strings.TrimSpace(arg)
if arg == "" {
    reply("usage: /show <path[:line]>")
    return
}
req, err := buildReferenceViewRequest(arg, workspaceDir)
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(rawRef) == "" {
    reply("usage: /show <path[:line]>")
    return
}

Try / catch

req, err := buildReferenceViewRequest(arg, ws)
if err != nil {
    reply("could not read reference: " + err.Error())
    return
}

Prevention

When it happens

Trigger: Calling parseUserLocalReference (via buildReferenceViewRequest, e.g. from cmdShow or a message attachment handler) with `raw` empty or whitespace-only — e.g. a `/show` command with no argument, or an empty message attachment path.

Common situations: User sends `/show` with no arguments; the platform strips content so the reference string arrives as "" or " "; upstream message parsing extracts an empty path from a malformed card/button payload.

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/c905fa8138db1131. Report an issue: GitHub.