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 / sec-default / hooks / caught / admission-caught.ts
26 lines · 916 BRaw
1import { admissionFailure } from '../admission-failure'
2import { managedModsOnlyRefusal } from '../managed-mods-only-refusal'
3import { quietly } from '../quietly'
4import type Types from './types'
5
6/**
7 * The `plugin.register` hook's failure handler: the failed hook's last run
8 * when it made one, else the module is refused.
9 *
10 * It names the failure in the debug log; that call's outcome changes
11 * nothing of the answer.
12 *
13 * @param e the module being judged
14 * @param next the handler's continuation, with why the hook failed
15 * @param log the handler's own line to the debug log
16 * @returns the admission's answer
17 */
18export function admissionCaught<E extends Types.Judged, R>(
19 e: E,
20 next: Types.CaughtNext<E, R> & Types.Failed,
21 log: (line: string) => unknown,
22) {
23 quietly(() => log(admissionFailure(e.name, next.error)))
24
25 return next.called ? next(e) : { refuse: managedModsOnlyRefusal(e.name) }
26}