@@ -20,13 +20,13 @@ def __init__(self, fs_path, rt_load=False):
20
20
HelmScanner .__init__ (self )
21
21
self .fs_path = fs_path
22
22
23
- def check_and_yield_file (self , file_path ):
23
+ def _check_and_yield_file (self , file_path ):
24
24
"""
25
25
checks if the given file is yaml file and yield its components
26
26
:param str file_path: path of file to check and yield
27
27
"""
28
28
if GenericTreeScanner .is_yaml_file (file_path ):
29
- file_stream = open (file_path )
29
+ file_stream = open (file_path , encoding = 'utf8' )
30
30
yield from self ._yield_yaml_file (file_path , file_stream )
31
31
file_stream .close ()
32
32
@@ -35,7 +35,7 @@ def get_yamls(self):
35
35
Call this function to get a generator for all yaml files
36
36
"""
37
37
if os .path .isfile (self .fs_path ):
38
- yield from self .check_and_yield_file (self .fs_path )
38
+ yield from self ._check_and_yield_file (self .fs_path )
39
39
return
40
40
41
41
if self .fs_path .endswith ('**' ):
@@ -46,18 +46,21 @@ def get_yamls(self):
46
46
def _scan_dir_for_yamls (self , dir_path , recursive ):
47
47
for root , sub_dirs , files in os .walk (dir_path ):
48
48
for file in files :
49
- if self .is_helm_chart (file ):
50
- file_name , file_content = self .parse_chart (root )
51
- file_stream = io .StringIO (file_content )
52
- yield from self ._yield_yaml_file (file_name , file_stream )
53
- file_stream .close ()
54
- else :
55
- full_path = os .path .abspath (os .path .join (root , file ))
56
- # skip if file was resolved by HELM or Helm template
57
- if self .is_yaml_file (full_path ) and not self .is_resolved_template (full_path ):
58
- if self .is_template (full_path ):
59
- print ('Warning: Skipping templated yaml file:' , full_path , file = stderr )
60
- else :
61
- yield from self .check_and_yield_file (os .path .join (root , file ))
49
+ try :
50
+ if self .is_helm_chart (file ):
51
+ file_name , file_content = self .parse_chart (root )
52
+ file_stream = io .StringIO (file_content )
53
+ yield from self ._yield_yaml_file (file_name , file_stream )
54
+ file_stream .close ()
55
+ else :
56
+ full_path = os .path .abspath (os .path .join (root , file ))
57
+ # skip if file was resolved by HELM or Helm template
58
+ if self .is_yaml_file (full_path ) and not self .is_resolved_template (full_path ):
59
+ if self .is_template (full_path ):
60
+ print ('Warning: Skipping templated yaml file:' , full_path , file = stderr )
61
+ else :
62
+ yield from self ._check_and_yield_file (os .path .join (root , file ))
63
+ except UnicodeDecodeError as decode_err :
64
+ print (f'Parse Error: While scanning { dir_path } , failed to decode { file } . error:\n { decode_err .reason } ' )
62
65
if not recursive :
63
66
break
0 commit comments