{"record":{"id":"87562e7645953ed7","repo":"LykosAI/StabilityMatrix","slug":"length-cannot-be-null-when-latenttype-is-hunyuan","errorCode":null,"errorMessage":"Length cannot be null when latentType is Hunyuan","messagePattern":"Length cannot be null when latentType is Hunyuan","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Extensions/ComfyNodeBuilderExtensions.cs","lineNumber":70,"sourceCode":"                    {\n                        Name = builder.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.EmptyFlux2LatentImage)),\n                        BatchSize = batchSize,\n                        Height = height,\n                        Width = width,\n                    }\n                )\n                .Output,\n            LatentType.Hunyuan => builder\n                .Nodes.AddTypedNode(\n                    new ComfyNodeBuilder.EmptyHunyuanLatentVideo\n                    {\n                        Name = builder.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.EmptyHunyuanLatentVideo)),\n                        BatchSize = batchSize,\n                        Height = height,\n                        Width = width,\n                        Length =\n                            length\n                            ?? throw new ValidationException(\n                                \"Length cannot be null when latentType is Hunyuan\"\n                            ),\n                    }\n                )\n                .Output,\n            _ => throw new ArgumentOutOfRangeException(nameof(latentType), latentType, null),\n        };\n\n        builder.Connections.Primary = primaryNodeConnection;\n        builder.Connections.PrimarySize = new Size(width, height);\n\n        // If batch index is selected, add a LatentFromBatch\n        if (batchIndex is not null)\n        {\n            builder.Connections.Primary = builder\n                .Nodes.AddTypedNode(\n                    new ComfyNodeBuilder.LatentFromBatch\n                    {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Extensions/ComfyNodeBuilderExtensions.cs#L52-L88","documentation":"ComfyNodeBuilderExtensions.SetupEmptyLatentSource builds a ComfyUI latent node for the requested latentType. The Hunyuan branch (EmptyHunyuanLatentVideo) requires a frame Length, which has no default; if the caller supplies null length, the builder throws ValidationException stating that Length is mandatory when latentType is Hunyuan.","triggerScenarios":"Calling SetupEmptyLatentSource with latentType = Hunyuan and length = null (or omitting the length argument), e.g. when generating image latents instead of video.","commonSituations":"Code paths shared between standard image generation (no length needed) and Hunyuan video generation (length required) that forget to set a frame count; UI defaults not wired for Hunyuan workflows.","solutions":["Pass an explicit positive length (frame count) when latentType is Hunyuan.","Add a guard in the calling workflow to require a frame count for Hunyuan before invoking.","Default length to a sensible value (e.g. 1 or the workflow's frame count) when null for Hunyuan."],"exampleFix":"// before\nvar latent = builder.SetupEmptyLatentSource(latentType, width, height, batchSize, length: null);\n\n// after\nvar frames = latentType == LatentType.Hunyuan ? (length ?? 25) : null;\nvar latent = builder.SetupEmptyLatentSource(latentType, width, height, batchSize, length: frames);","handlingStrategy":"validation","validationCode":"if (latentType == LatentType.Hunyuan && length is null or <= 0)\n    throw new InvalidOperationException(\"Provide a frame length for Hunyuan latents.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var latent = builder.SetupEmptyLatentSource(latentType, w, h, batch, length);\n}\ncatch (ValidationException ex)\n{\n    notifier.ShowError(ex.Message);\n}","preventionTips":["Always supply a frame count for video latent types like Hunyuan","Gate Hunyuan workflows behind UI fields that require Length","Share a single workflow builder that validates latentType-specific requirements"],"tags":["comfyui","validation","latent","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}