mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-01 03:31:58 +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 objectInfoUnsafe = await resp.json()
|
||||||
const objectInfo: Record<string, ComfyNodeDef> = {}
|
const objectInfo: Record<string, ComfyNodeDef> = {}
|
||||||
for (const key in objectInfoUnsafe) {
|
for (const key in objectInfoUnsafe) {
|
||||||
try {
|
const validatedDef = await validateComfyNodeDef(
|
||||||
objectInfo[key] = validateComfyNodeDef(objectInfoUnsafe[key])
|
objectInfoUnsafe[key],
|
||||||
} catch (e) {
|
/* onError=*/ (errorMessage: string) => {
|
||||||
console.warn('Ignore node definition: ', key)
|
console.warn(
|
||||||
console.error(e)
|
`Skipping invalid node definition: ${key}. See debug log for more information.`
|
||||||
|
)
|
||||||
|
console.debug(errorMessage)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (validatedDef !== null) {
|
||||||
|
objectInfo[key] = validatedDef
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return objectInfo
|
return objectInfo
|
||||||
|
|||||||
@@ -285,15 +285,17 @@ export type ComfyInputsSpec = z.infer<typeof zComfyInputsSpec>
|
|||||||
export type ComfyOutputTypesSpec = z.infer<typeof zComfyOutputTypesSpec>
|
export type ComfyOutputTypesSpec = z.infer<typeof zComfyOutputTypesSpec>
|
||||||
export type ComfyNodeDef = z.infer<typeof zComfyNodeDef>
|
export type ComfyNodeDef = z.infer<typeof zComfyNodeDef>
|
||||||
|
|
||||||
export function validateComfyNodeDef(data: any): ComfyNodeDef {
|
export async function validateComfyNodeDef(
|
||||||
const result = zComfyNodeDef.safeParse(data)
|
data: any,
|
||||||
|
onError: (error: string) => void = console.warn
|
||||||
|
): Promise<ComfyNodeDef | null> {
|
||||||
|
const result = await zComfyNodeDef.safeParseAsync(data)
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
const zodError = fromZodError(result.error)
|
const zodError = fromZodError(result.error)
|
||||||
const error = new Error(
|
onError(
|
||||||
`Invalid ComfyNodeDef: ${JSON.stringify(data)}\n${zodError.message}`
|
`Invalid ComfyNodeDef: ${JSON.stringify(data)}\n${zodError.message}`
|
||||||
)
|
)
|
||||||
error.cause = zodError
|
return null
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
return result.data
|
return result.data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ const EXAMPLE_NODE_DEF: ComfyNodeDef = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('validateNodeDef', () => {
|
describe('validateNodeDef', () => {
|
||||||
it('Should accept a valid node definition', () => {
|
it('Should accept a valid node definition', async () => {
|
||||||
expect(() => validateComfyNodeDef(EXAMPLE_NODE_DEF)).not.toThrow()
|
expect(await validateComfyNodeDef(EXAMPLE_NODE_DEF)).not.toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe.each([
|
describe.each([
|
||||||
@@ -35,14 +35,16 @@ describe('validateNodeDef', () => {
|
|||||||
])(
|
])(
|
||||||
'validateComfyNodeDef with various input spec formats',
|
'validateComfyNodeDef with various input spec formats',
|
||||||
(inputSpec, expected) => {
|
(inputSpec, expected) => {
|
||||||
it(`should accept input spec format: ${JSON.stringify(inputSpec)}`, () => {
|
it(`should accept input spec format: ${JSON.stringify(inputSpec)}`, async () => {
|
||||||
expect(
|
expect(
|
||||||
validateComfyNodeDef({
|
(
|
||||||
...EXAMPLE_NODE_DEF,
|
await validateComfyNodeDef({
|
||||||
input: {
|
...EXAMPLE_NODE_DEF,
|
||||||
required: inputSpec
|
input: {
|
||||||
}
|
required: inputSpec
|
||||||
}).input.required.ckpt_name
|
}
|
||||||
|
})
|
||||||
|
).input.required.ckpt_name
|
||||||
).toEqual(expected)
|
).toEqual(expected)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -57,15 +59,15 @@ describe('validateNodeDef', () => {
|
|||||||
])(
|
])(
|
||||||
'validateComfyNodeDef rejects with various input spec formats',
|
'validateComfyNodeDef rejects with various input spec formats',
|
||||||
(inputSpec) => {
|
(inputSpec) => {
|
||||||
it(`should accept input spec format: ${JSON.stringify(inputSpec)}`, () => {
|
it(`should accept input spec format: ${JSON.stringify(inputSpec)}`, async () => {
|
||||||
expect(() =>
|
expect(
|
||||||
validateComfyNodeDef({
|
await validateComfyNodeDef({
|
||||||
...EXAMPLE_NODE_DEF,
|
...EXAMPLE_NODE_DEF,
|
||||||
input: {
|
input: {
|
||||||
required: inputSpec
|
required: inputSpec
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
).toThrow()
|
).toBeNull()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -76,8 +78,9 @@ describe('validateNodeDef', () => {
|
|||||||
fs.readFileSync(path.resolve('./tests-ui/data/object_info.json'))
|
fs.readFileSync(path.resolve('./tests-ui/data/object_info.json'))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
nodeDefs.forEach((nodeDef) => {
|
|
||||||
expect(() => validateComfyNodeDef(nodeDef)).not.toThrow()
|
for (const nodeDef of nodeDefs) {
|
||||||
})
|
expect(await validateComfyNodeDef(nodeDef)).not.toBeNull()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user