Skip to content

Commit 5879e84

Browse files
committed
cfengine dev lint-docs: Added better error handling for snippets which are not valid policy
Signed-off-by: Ole Herman Schumacher Elgesem <[email protected]>
1 parent 5c596cf commit 5879e84

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/cfengine_cli/docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def update_docs() -> int:
346346
output_check=False,
347347
autoformat=True,
348348
replace=True,
349-
cleanup=True,
349+
cleanup=False,
350350
)
351351
return 0
352352

src/cfengine_cli/lint.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ def lint_policy_file(
122122
lines = original_data.decode().split("\n")
123123

124124
root_node = tree.root_node
125+
if root_node.type != "source_file":
126+
print(f"Error: Failed to parse snippet ('{filename}') - Is this valid CFEngine policy?")
127+
print("")
128+
lines = original_data.decode().split("\n")
129+
if not len(lines) <= 5:
130+
lines = lines[:4] + ["..."]
131+
for line in lines:
132+
print(" " + line)
133+
print("")
134+
return 1
125135
assert root_node.type == "source_file"
126136
errors = 0
127137
if not root_node.children:

0 commit comments

Comments
 (0)