# vtkExtractSelection with empty vtkSelection uninformative error message

**URL:** <https://discourse.vtk.org/t/vtkextractselection-with-empty-vtkselection-uninformative-error-message/15852>\
**Category:** Development\
**Created:** [July 23, 2025, 5:21pm UTC](https://discourse.vtk.org/t/vtkextractselection-with-empty-vtkselection-uninformative-error-message/15852 "2025-07-23T17:21:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![manik](https://discourse.vtk.org/user_avatar/discourse.vtk.org/manik/32/9300_2.png) [@manik](https://discourse.vtk.org/u/manik)\
**Post date:** [July 23, 2025, 5:21pm UTC](https://discourse.vtk.org/t/vtkextractselection-with-empty-vtkselection-uninformative-error-message/15852/1 "2025-07-23T17:21:51Z")

</div>

Hi,  
I would like to suggest an improvement in vtkExtractSelection because I had some difficulty understanding a bug in my software:  
if vtkExtractSelection is updated but the vtkSelection used as inputData is empty (no vtkSelectionNode), an error is displayed in the console.  
Two suggestions:

- the behavior should not trigger an error, and just not extract anything with no error message
- If the current behavior is needed for some reason, at least the message in the console should report the real issue (no vtkSelectionNode in the vtkSelection) instead of this:  
`2025-07-23 18:59:54.470 ( 0.001s) [2E83B780]vtkExtractSelection.cxx:201 ERR| vtkExtractSelection (0x6172983bff30): Selection has selection nodes with inconsistent field types. 2025-07-23 18:59:54.470 ( 0.001s) [2E83B780] vtkExecutive.cxx:752 ERR| vtkCompositeDataPipeline (0x6172983c08e0): Algorithm vtkExtractSelection(0x6172983bff30) returned failure for request: vtkInformation (0x6172983c12a0) Debug: Off Modified Time: 388 Reference Count: 1 Registered Events: (none) Request: REQUEST_DATA FROM_OUTPUT_PORT: 0 ALGORITHM_AFTER_FORWARD: 1 FORWARD_DIRECTION: 0`

To reproduce the issue, just get [ExtractSelection example](https://examples.vtk.org/site/Cxx/PolyData/ExtractSelection/) and either remove the `selection.AddNode(selectionNode);` (line 54) or add `selection->RemoveAllNodes();` (in line 55)

The message comes from [vtkExtractSelection::RequestData](https://github.com/Kitware/VTK/blob/4a7079daac6125035e7ff66526127c3a5fdd142d/Filters/Extraction/vtkExtractSelection.cxx#L273) because the call to [vtkExtractSelection::GetAttributeTypeOfSelection](https://github.com/Kitware/VTK/blob/4a7079daac6125035e7ff66526127c3a5fdd142d/Filters/Extraction/vtkExtractSelection.cxx#L150C52-L150C79) sets the parameter sane to false if the vtkSelection has no nodes.

There might be a good reason for this error being triggered by an empty vtkSelection, but if the message was improved it might save some debugging time for others !  
Thanks !

---

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [July 24, 2025, 11:30am UTC](https://discourse.vtk.org/t/vtkextractselection-with-empty-vtkselection-uninformative-error-message/15852/2 "2025-07-24T11:30:32Z")

</div>

> [@manik](#):
>
> the behavior should not trigger an error, and just not extract anything with no error message

That sounds fine to me, please open a MR to change that behavior.

---

<div class="post-metadata">

**Author:** ![manik](https://discourse.vtk.org/user_avatar/discourse.vtk.org/manik/32/9300_2.png) [@manik](https://discourse.vtk.org/u/manik)\
**Post date:** [July 25, 2025, 3:38pm UTC](https://discourse.vtk.org/t/vtkextractselection-with-empty-vtkselection-uninformative-error-message/15852/3 "2025-07-25T15:38:59Z")

</div>

I am using VTK 9.1 from Ubuntu 24.04, but it seems that the current vtk already has a fix for this, which checks the number of nodes. I suppose using the current vtk should solve this issue.  
Thanks !
