// Before: every exit path returned the same shape with no signal. // After: each exit logs a distinct reason. Total addition: 6 lines. const timeoutMs = opts.timeoutMs ?? 2500 const apiKey = process.env.OPENAI_API_KEY if (!apiKey) { console.warn(JSON.stringify({ component: 'scanLayer4Sync', reason: 'no_key', durationMs: Date.now() - startTime })) return { findings: [], timedOut: true } } try { const res = await fetch('https://api.openai.com/v1/chat/completions', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}` }, body: JSON.stringify({ model: 'gpt-4o-mini', temperature: 0, response_format: { type: 'json_object' }, messages: [/* ... */] }), signal: AbortSignal.timeout(timeoutMs), }) if (!res.ok) { console.warn(JSON.stringify({ component: 'scanLayer4Sync', reason: 'http_status', durationMs: Date.now() - startTime, status: res.status })) return { findings: [], timedOut: true } } // ... no_content / parse_fail / empty_results checks, each with their own warn ... } catch (err) { const errorName = err instanceof Error ? err.name : undefined console.warn(JSON.stringify({ component: 'scanLayer4Sync', reason: 'caught', durationMs: Date.now() - startTime, ...(errorName ? { errorName } : {}) })) return { findings: [], timedOut: true } }
85705ea8-f998-4a60-bc80-70e3181a82ee
// Before: every exit path returned the same shape with no signal.
// After: each exit logs a distinct reason. Total addition: 6 lines.
const timeoutMs = opts.timeoutMs ?? 2500
const apiKey = process.env.OPENAI_API_KEY
if (!apiKey) {
console.warn(JSON.stringify({ component: 'scanLayer4Sync', reason: 'no_key', durationMs: Date.now() - startTime }))
return { findings: [], timedOut: true }
}
try {
const res = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: Bearer ${apiKey} },
body: JSON.stringify({ model: 'gpt-4o-mini', temperature: 0, response_format: { type: 'json_object' }, messages: [/* ... */] }),
signal: AbortSignal.timeout(timeoutMs),
})
if (!res.ok) {
console.warn(JSON.stringify({ component: 'scanLayer4Sync', reason: 'http_status', durationMs: Date.now() - startTime, status: res.status }))
return { findings: [], timedOut: true }
}
// ... no_content / parse_fail / empty_results checks, each with their own warn ...
} catch (err) {
const errorName = err instanceof Error ? err.name : undefined
console.warn(JSON.stringify({ component: 'scanLayer4Sync', reason: 'caught', durationMs: Date.now() - startTime, ...(errorName ? { errorName } : {}) }))
return { findings: [], timedOut: true }
}