Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/partial-message-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/board': patch
---

`board read` with a message ID cut short (like `msg_<thread>` without its `_<n>`) says it looks like one instead of only that no channel has that name, and suggests the thread's root when the thread's part is whole.
14 changes: 13 additions & 1 deletion packages/board/src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,16 @@ const tooLarge = (path: string) =>
/** Whether an ID goes in and out bare: a number, or one Vercel's API hands out (`msg_…`, or a thread's `thr_…`), a message even where a channel has its name. */
const bareId = (value: string) => /^\d+$/.test(value) || isApiMessageId(value) || apiThreadRoot(value) !== null

/**
* What a value that starts like Vercel's message or thread ID but isn't a whole one (a copy cut short) would be
* whole: its thread's root, when the thread's part is all there, or only that it's cut short.
*/
const partialApiId = (value: string): { root: string | null } | null => {
if (!/^(?:msg|thr)_[0-9a-f-]/.test(value) || bareId(value)) return null
const thread = /^(?:msg|thr)_([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})_?$/.exec(value)
return { root: thread ? `msg_${thread[1]}_1` : null }
}

/** Whether an argument names a message rather than a channel: `#<id>`, or an ID that goes bare. */
const isMessageRef = (value: string) => /^#[^\s/]+$/.test(value) || bareId(value)

Expand Down Expand Up @@ -1547,12 +1557,14 @@ async function run(command: string | undefined, args: string[]): Promise<number>
// Every channel, a page at a time: a name close to the one typed could be any of them.
const channels = (await everyChannel(board)).map((c) => c.path)
if (!channels.some((path) => path === target || path.startsWith(target.replace(/\/?$/, '/')))) {
const guess = closest(target, channels)
const partial = partialApiId(target)
const guess = partial ? partial.root : closest(target, channels)
throw new Failed({
class: 'not_found',
reason: 'channel_not_found',
message: `Couldn't find channel ${target}.${guess ? ` Did you mean ${guess}?` : ''}`,
details: [
...(partial ? [`It looks like a message ID cut short: a whole one is msg_<thread>_<n>, ending in the message's number. Check the full ID.`] : []),
'A channel appears with its first post: one nobody has posted in yet is not there to read.',
...(teamDefault ? [`This is ${teamDefault.team ?? 'the team'}'s default board: --name reads another of its boards.`] : []),
],
Expand Down
6 changes: 6 additions & 0 deletions packages/board/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,12 @@ describe('cli', () => {

// A typo'd channel is an error, not an empty read; an empty read in a real channel isn't.
expect(await vb(['read', 'open-wrok'])).toMatchObject({ code: 1, stdout: '', stderr: expect.stringMatching(/^error: Couldn't find channel open-wrok\. Did you mean open-work\?\n/) })
// A message ID cut short isn't a channel: the error says so, and names its thread's root when it can.
const thread = '73a86530-2081-47c4-b7a2-479632af9026'
for (const cut of [`msg_${thread}`, `msg_${thread}_`, `thr_${thread}_`])
expect(await vb(['read', cut]), cut).toMatchObject({ code: 1, stdout: '', stderr: expect.stringMatching(new RegExp(`^error: Couldn't find channel ${cut}\\. Did you mean msg_${thread}_1\\?\\n.*message ID cut short`)) })
expect(await vb(['read', 'msg_73a86530-2081'])).toMatchObject({ code: 1, stderr: expect.stringMatching(/^error: Couldn't find channel msg_73a86530-2081\.\n.*message ID cut short/) })
expect((await vb(['read', 'open-wrok'])).stderr).not.toContain('message ID')
expect(await vb(['read', 'open-work', '--text', 'nothing like this'])).toMatchObject({ code: 0, stdout: expect.stringMatching(/^open-work · 0 threads · cursor \d+\n\nnew since then: vb read open-work --text 'nothing like this' --after \d+\n$/) })
expect(await vb(['read', 'open-work', '--messages'])).toMatchObject({ code: 2 })
})
Expand Down