mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 02:02:08 +00:00
Reduce loglevel on node def validation (#295)
* Lower the loglevel of node def validation messages * Fix tests
This commit is contained in:
@@ -249,11 +249,17 @@ class ComfyApi extends EventTarget {
|
||||
const objectInfoUnsafe = await resp.json()
|
||||
const objectInfo: Record<string, ComfyNodeDef> = {}
|
||||
for (const key in objectInfoUnsafe) {
|
||||
try {
|
||||
objectInfo[key] = validateComfyNodeDef(objectInfoUnsafe[key])
|
||||
} catch (e) {
|
||||
console.warn('Ignore node definition: ', key)
|
||||
console.error(e)
|
||||
const validatedDef = await validateComfyNodeDef(
|
||||
objectInfoUnsafe[key],
|
||||
/* onError=*/ (errorMessage: string) => {
|
||||
console.warn(
|
||||
`Skipping invalid node definition: ${key}. See debug log for more information.`
|
||||
)
|
||||
console.debug(errorMessage)
|
||||
}
|
||||
)
|
||||
if (validatedDef !== null) {
|
||||
objectInfo[key] = validatedDef
|
||||
}
|
||||
}
|
||||
return objectInfo
|
||||
|
||||
@@ -285,15 +285,17 @@ export type ComfyInputsSpec = z.infer<typeof zComfyInputsSpec>
|
||||
export type ComfyOutputTypesSpec = z.infer<typeof zComfyOutputTypesSpec>
|
||||
export type ComfyNodeDef = z.infer<typeof zComfyNodeDef>
|
||||
|
||||
export function validateComfyNodeDef(data: any): ComfyNodeDef {
|
||||
const result = zComfyNodeDef.safeParse(data)
|
||||
export async function validateComfyNodeDef(
|
||||
data: any,
|
||||
onError: (error: string) => void = console.warn
|
||||
): Promise<ComfyNodeDef | null> {
|
||||
const result = await zComfyNodeDef.safeParseAsync(data)
|
||||
if (!result.success) {
|
||||
const zodError = fromZodError(result.error)
|
||||
const error = new Error(
|
||||
onError(
|
||||
`Invalid ComfyNodeDef: ${JSON.stringify(data)}\n${zodError.message}`
|
||||
)
|
||||
error.cause = zodError
|
||||
throw error
|
||||
return null
|
||||
}
|
||||
return result.data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user