mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 18:40:50 +08:00 
			
		
		
		
	Improve exception if a (multi)selection prompt is used incorrectly
Before this commit, the selection prompt would throw an `InvalidOperationException` (Sequence contains no elements) and the multi selection prompt would throw an `ArgumentOutOfRangeException` (Index was out of range. Must be non-negative and less than the size of the collection.) Both would occur because the prompts were never meant to be empty.
This commit is contained in:
		
				
					committed by
					
						
						Patrik Svensson
					
				
			
			
				
	
			
			
			
						parent
						
							b470af11f7
						
					
				
				
					commit
					c70a8b8fc5
				
			@@ -42,6 +42,11 @@ internal sealed class ListPrompt<T>
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var nodes = tree.Traverse().ToList();
 | 
			
		||||
        if (nodes.Count == 0)
 | 
			
		||||
        {
 | 
			
		||||
            throw new InvalidOperationException("Cannot show an empty selection prompt. Please call the AddChoice() method to configure the prompt.");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var state = new ListPromptState<T>(nodes, converter, _strategy.CalculatePageSize(_console, nodes.Count, requestedPageSize), wrapAround, selectionMode, skipUnselectableItems, searchEnabled);
 | 
			
		||||
        var hook = new ListPromptRenderHook<T>(_console, () => BuildRenderable(state));
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user