spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / telemetry / hooks / answer-of / answer-of.ts
24 lines · 735 BRaw
1import Entries from '../entries'
2
3/**
4 * A row's queueing as the hook on its event answers it: `{ value }` once
5 * the row is queued, and a refused entry as `{ deny }` with its reason, so
6 * the caller's promise rejects naming what was wrong.
7 *
8 * Anything else that went wrong is thrown on: the hook failed, and the
9 * engine goes on beneath it as it does for any failed hook.
10 *
11 * @param queued the queueing, settled once the entry is checked and queued
12 * @returns the hook's answer
13 */
14export const answerOf = (queued: Promise<void>) =>
15 queued.then(
16 () => ({ value: undefined }),
17 (error: unknown) => {
18 if (Entries.isRefusedEntry(error)) {
19 return { deny: error.what }
20 }
21
22 throw error
23 },
24 )