{"record":{"id":"404d85e0dd8ab420","repo":"Unity-Technologies/UnityCsReference","slug":"must-not-be-empty","errorCode":null,"errorMessage":"Must not be empty.","messagePattern":"Must not be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Audio/AudioRandomContainerExtensions.cs","lineNumber":43,"sourceCode":"            throw new ArgumentOutOfRangeException(nameof(count), \"Must be greater than zero.\");\n\n        AddElementsInner(container, count, (i, element) => { });\n    }\n\n    /// <summary>\n    /// Adds a given number of new <see cref=\"AudioContainerElement\"/> objects with clips assigned to <see cref=\"AudioRandomContainer.elements\"/>.\n    /// </summary>\n    /// <param name=\"container\">The instance to add the elements to.</param>\n    /// <param name=\"clips\">An array of <see cref=\"AudioClip\"/> objects to be assigned to each new element.</param>\n    internal static void AddElements(this AudioRandomContainer container, AudioClip[] clips)\n    {\n        ValidateContainer(container);\n\n        if (clips == null)\n            throw new ArgumentNullException(nameof(clips));\n\n        if (clips.Length == 0)\n            throw new ArgumentException(\"Must not be empty.\", nameof(clips));\n\n        AddElementsInner(container, clips.Length, (i, element) =>\n        {\n            if (clips[i] != null)\n                element.audioClip = clips[i];\n        });\n    }\n\n    static void ValidateContainer(AudioRandomContainer container)\n    {\n        if (container == null)\n            throw new ArgumentNullException(nameof(container));\n\n        if (!EditorUtility.IsPersistent(container))\n            throw new ArgumentException(\"Must be a persistent asset.\", nameof(container));\n    }\n\n    static void AddElementsInner(AudioRandomContainer container, int count,","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Audio/AudioRandomContainerExtensions.cs#L25-L61","documentation":"ArgumentException thrown by AudioRandomContainerExtensions.AddElements(AudioClip[] clips) when the clips array has zero elements. The guard prevents adding zero elements (a no-op that would still create an undo group), ensuring the operation is meaningful.","triggerScenarios":"Calling container.AddElements(new AudioClip[0]) or passing an array whose Length is 0. Occurs when filtering operations remove all clips, when a selection contains no audio clips, or when a UI operation results in an empty clips list.","commonSituations":"Drag-and-drop handlers where only non-AudioClip assets were dropped, filtered lists where no clips match the filter criteria, SerializedProperty arrays with arraySize 0, batch operations on empty selections.","solutions":["Check clips.Length > 0 before calling AddElements.","Guard the call site: if (clips != null && clips.Length > 0) container.AddElements(clips);","If filtering clips, skip the AddElements call entirely when the filtered result is empty.","Validate user selection contains at least one AudioClip before proceeding."],"exampleFix":"// before\ncontainer.AddElements(selectedClips); // may be empty\n// after\nif (selectedClips != null && selectedClips.Length > 0)\n    container.AddElements(selectedClips);","handlingStrategy":"validation","validationCode":"// Check for non-empty clips before calling AddElements\nif (clips != null && clips.Length > 0)\n    container.AddElements(clips);","typeGuard":"static bool HasClips(AudioClip[] clips) => clips != null && clips.Length > 0;","tryCatchPattern":null,"preventionTips":["Check clips.Length > 0 alongside null before calling AddElements.","Filter out empty selections in drag-and-drop handlers before proceeding.","Skip AddElements when the filtered clip list is empty.","Log a user-friendly message when no valid clips are available instead of throwing."],"tags":["audio","editor","validation","empty-check","argument-validation","audio-random-container"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}