Skip to content

fix(terminal): guard formatDocsLink against undefined path#66754

Open
MukundaKatta wants to merge 2 commits intoopenclaw:mainfrom
MukundaKatta:fix/format-docs-link-undefined-path
Open

fix(terminal): guard formatDocsLink against undefined path#66754
MukundaKatta wants to merge 2 commits intoopenclaw:mainfrom
MukundaKatta:fix/format-docs-link-undefined-path

Conversation

@MukundaKatta
Copy link
Copy Markdown

Summary

  • Fixes [Bug] openclaw configure TypeError: Cannot read properties of undefined (reading 'trim') #66718
  • openclaw configure crashed on the Channels section with TypeError: Cannot read properties of undefined (reading 'trim') when a ChannelMeta entry reached formatDocsLink with an undefined/empty `docsPath`.
  • Accept `path: string | undefined | null` and fall back to the docs root when the path is missing, so the configure wizard renders a usable (if generic) docs link instead of throwing.
  • Add `src/terminal/links.test.ts` with regression coverage for the undefined/null paths and the existing shape contracts.

Why

This is a pure defensive fix at the helper: a missing `docsPath` is a latent data bug elsewhere, but the user-facing effect was a wizard crash. Stopping the crash restores the wizard; the underlying data gap is a separate issue.

Test plan

  • `pnpm vitest run src/terminal/links.test.ts` — 6/6 pass
  • `pnpm check` (via pre-commit hook) — green
  • No behavior change for existing callers with a valid `path` (covered by the new absolute / relative / slash-prefix tests)

AI-assisted disclosure

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 14, 2026

Greptile Summary

Adds a null/undefined guard to formatDocsLink in src/terminal/links.ts so the configure wizard no longer crashes when a ChannelMeta entry omits docsPath. The signature is widened to string | undefined | null and missing paths fall back to the docs root. All existing callers pass string literals, so the change is fully non-breaking.

Confidence Score: 5/5

  • Safe to merge — narrow defensive fix with good regression coverage and no impact on existing callers.
  • The only finding is a P2 style nit (redundant double-cast in tests). The fix itself is correct, non-breaking, and well-tested.
  • No files require special attention.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/terminal/links.test.ts
Line: 10

Comment:
**Unnecessary double-cast in tests**

Since the function signature was just updated to `path: string | undefined | null`, passing `undefined` or `null` is now fully typed — the `as unknown as string` double-cast is no longer needed and slightly obscures intent. The same applies to lines 16 and 21.

```suggestion
      formatDocsLink(undefined, "label", { force: false }),
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(terminal): guard formatDocsLink agai..." | Re-trigger Greptile

Comment thread src/terminal/links.test.ts Outdated
// when a ChannelMeta entry reached this helper without a `docsPath`.
it("does not throw when path is undefined", () => {
expect(() =>
formatDocsLink(undefined as unknown as string, "label", { force: false }),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unnecessary double-cast in tests

Since the function signature was just updated to path: string | undefined | null, passing undefined or null is now fully typed — the as unknown as string double-cast is no longer needed and slightly obscures intent. The same applies to lines 16 and 21.

Suggested change
formatDocsLink(undefined as unknown as string, "label", { force: false }),
formatDocsLink(undefined, "label", { force: false }),
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/terminal/links.test.ts
Line: 10

Comment:
**Unnecessary double-cast in tests**

Since the function signature was just updated to `path: string | undefined | null`, passing `undefined` or `null` is now fully typed — the `as unknown as string` double-cast is no longer needed and slightly obscures intent. The same applies to lines 16 and 21.

```suggestion
      formatDocsLink(undefined, "label", { force: false }),
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Author

@MukundaKatta MukundaKatta Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in ce7f6c0 — dropped the as unknown as string casts on lines 10, 16, and 21 now that the signature accepts undefined | null directly. Tests still pass (6/6).

MukundaKatta added a commit to MukundaKatta/openclaw that referenced this pull request Apr 14, 2026
…tests

Greptile review nit on openclaw#66754: the `formatDocsLink` signature already
accepts `string | undefined | null`, so the double-cast in the
regression tests is no longer needed and slightly obscures intent.
@MukundaKatta
Copy link
Copy Markdown
Author

Linking duplicate user reports of the same formatDocsLink panic so they can be closed if this lands:

All four hit the same Cannot read properties of undefined (reading 'trim') from formatDocsLink via formatChannelSelectionLine — same code path, same cause as #66718. The fix in this PR should resolve all of them.

@winrid
Copy link
Copy Markdown

winrid commented Apr 15, 2026

Confirmed this patch fixed my setup flow as well (arcee+telegram).

Running `openclaw configure` crashed on the Channels section with:

    TypeError: Cannot read properties of undefined (reading 'trim')
        at formatDocsLink (src/terminal/links.ts)
        at formatChannelSelectionLine (src/channels/registry.ts)

This happens when a `ChannelMeta` entry reaches `formatDocsLink` with
an `undefined` (or empty) `docsPath`. The existing code unconditionally
called `path.trim()`.

Accept `path: string | undefined | null` and fall back to the docs
root when no path is provided, so the configure wizard can still
render a usable (if generic) docs link instead of crashing.

Add `src/terminal/links.test.ts` with regression coverage for the
undefined/null paths plus the existing shape contracts.

Fixes openclaw#66718

AI-assisted: drafted with Claude. Tested with `pnpm vitest run
src/terminal/links.test.ts` (6/6 pass).
@MukundaKatta MukundaKatta force-pushed the fix/format-docs-link-undefined-path branch from ce7f6c0 to a702c35 Compare April 18, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] openclaw configure TypeError: Cannot read properties of undefined (reading 'trim')

2 participants