Skip to content

CFE-3866: Add workaround for set_variable_values_ini errors when section doesn't exist#3128

Merged
nickanderson merged 2 commits intocfengine:masterfrom
nickanderson:CFE-3866-fix
Apr 16, 2026
Merged

CFE-3866: Add workaround for set_variable_values_ini errors when section doesn't exist#3128
nickanderson merged 2 commits intocfengine:masterfrom
nickanderson:CFE-3866-fix

Conversation

@nickanderson
Copy link
Copy Markdown
Member

@nickanderson nickanderson commented Apr 15, 2026

This test demonstrates the bug where set_variable_values_ini() emits
'could not select an edit region' errors when called on a file where
the promised section doesn't exist yet.

The test creates an empty file and uses set_variable_values_ini() to
add a section with keys. Without the fix, this produces multiple errors
even though the section is created by the same bundle.

Together with cfengine/core#6072

Ticket: CFE-3866

@nickanderson nickanderson force-pushed the CFE-3866-fix branch 2 times, most recently from d11c06d to 0cbcc42 Compare April 15, 2026 22:24
@nickanderson
Copy link
Copy Markdown
Member Author

Together with cfengine/core#6072

@nickanderson
Copy link
Copy Markdown
Member Author

@cf-bottom jenkins please

@cf-bottom
Copy link
Copy Markdown

@nickanderson nickanderson force-pushed the CFE-3866-fix branch 2 times, most recently from a64d34b to f95d2fe Compare April 16, 2026 02:31
@nickanderson
Copy link
Copy Markdown
Member Author

@cf-bottom jenkins please

@cf-bottom
Copy link
Copy Markdown

Comment thread lib/files.cf Outdated
Comment thread lib/files.cf Outdated
Comment thread lib/files.cf Outdated
Comment thread lib/files.cf Outdated
Comment thread tests/acceptance/lib/files/set_variable_values_ini_missing_section.cf Outdated
Copy link
Copy Markdown
Contributor

@craigcomstock craigcomstock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

Comment thread tests/acceptance/lib/files/set_variable_values_ini_missing_section.cf Outdated
Modified set_variable_values_ini() to check if the section exists before
attempting to use select_region. When the section doesn't exist yet, lines
are inserted after the section header instead of using select_region.

This prevents 'could not select an edit region' errors when the section
is being created by the same bundle in an earlier promise.

The fix:
- Detects if section exists using regline()
- For existing sections: uses select_region (original behavior)
- For new sections: inserts after section header using location => after()
- Adds unique handles to distinguish the two insertion paths

Ticket: CFE-3866
Changelog: Title
This test demonstrates the bug where set_variable_values_ini() emits
'could not select an edit region' errors when called on a file where
the promised section doesn't exist yet.

The test creates an empty file and uses set_variable_values_ini() to
add sections with keys. Without the fix in the previous commit, this
produces multiple errors even though the sections are created by the
same bundle.

Ticket: CFE-3866
Changelog: None
@nickanderson nickanderson merged commit a8ba553 into cfengine:master Apr 16, 2026
7 checks passed
@nickanderson nickanderson changed the title CFE-3866: Add test for CFE-3866: set_variable_values_ini errors when section doesn't exist CFE-3866: Add workaround for set_variable_values_ini errors when section doesn't exist Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants