@@ -26,7 +26,7 @@ import { fileURLToPath } from "node:url";
2626import { parsePolicy , scopeMatches , discoverConfigPolicy , parseUnknownAliases , discoverConfigText ,
2727 evaluatePolicy , reportNetClasses , resolveReasonClasses , discoverConfigPath ,
2828 policyVocabularyAnchor , policyErrorText , policyUnreadable , policyZeroRules ,
29- fatalPolicyErrors , refusalVerdict , unanswerableScoped , wholePolicyUnanswerable , reportUnits , acceptedUnitsOver , acceptReviewOver , } from "./policy.mjs" ;
29+ fatalPolicyErrors , refusalVerdict , unanswerableScoped , wholePolicyUnanswerable , reportUnits , acceptedUnitsOver , acceptReviewOver , onPolicyExit , } from "./policy.mjs" ;
3030import { accepts as acceptsVerb , reasonOf , noReportMessage } from "./accepts.mjs" ;
3131import { gateCore , runAcceptsGate } from "./gate-core.mjs" ;
3232import { hasReport , refusalMarkerFor , refusalSentence } from "./query-core.mjs" ;
@@ -1281,10 +1281,11 @@ const usage = () => {
12811281// listener below records the code and RETURNS, and the process ends naturally — the isolate is disposed before the
12821282// platform, which does not hang. Every `catch` in this file rethrows a QueryExit first, so no handler can swallow
12831283// an exit and carry on; this file has no `finally` and no `await`, so nothing else runs on the way out. The same
1284- // shape as gate-core's `GateDone`, which `accepts` already relies on. `policy.mjs`'s unreadable-config refusal is
1285- // shared with scan.mjs (whose catches do not rethrow) and keeps its `process.exit` .
1286- class QueryExit extends Error { constructor ( code ) { super ( "candor-ts-query exit" ) ; this . code = code ; } }
1284+ // shape as gate-core's `GateDone`, which `accepts` already relies on. `policy.mjs`'s unreadable-config refusal reaches
1285+ // here through `onPolicyExit(qexit)` below, so it is a QueryExit too .
1286+ class QueryExit extends Error { constructor ( code ) { super ( "candor-ts-query exit" ) ; this . code = code ; this . candorExit = true ; } }
12871287const qexit = ( code ) => { throw new QueryExit ( code ) ; } ;
1288+ onPolicyExit ( qexit ) ; // policy.mjs's unreadable-config refusal arrives as a QueryExit, which every catch here rethrows
12881289process . on ( "uncaughtException" , ( e ) => {
12891290 if ( e instanceof QueryExit ) { if ( e . code !== undefined ) process . exitCode = e . code ; return ; }
12901291 console . error ( e ?. stack ?? String ( e ) ) ; // anything else is a crash: say so and exit 1, naturally
0 commit comments