chore(json): only print warning after stream finished

This commit is contained in:
AnotiaWang
2025-02-22 15:16:17 +08:00
parent 66c28978d1
commit 22ce46f173

View File

@ -70,14 +70,13 @@ export async function* parseStreamingJson<T extends z.ZodType>(
type: 'object', type: 'object',
value: parsed.value as DeepPartial<z.infer<T>>, value: parsed.value as DeepPartial<z.infer<T>>,
} }
} else {
console.debug(`Failed to parse JSON: ${removeJsonMarkdown(rawText)}`)
} }
} }
} }
// If the last chunk parses failed, return an error // If the last chunk parses failed, return an error
if (!isParseSuccessful) { if (!isParseSuccessful) {
console.warn(`[parseStreamingJson] Failed to parse JSON: ${removeJsonMarkdown(rawText)}`)
yield { yield {
type: 'bad-end', type: 'bad-end',
rawText, rawText,