@@ -1971,6 +1971,12 @@ def load_kubernetes_configuration(filename):
19711971 except OSError as ex :
19721972 if getattr (ex , 'errno' , 0 ) == errno .ENOENT :
19731973 raise CLIError ('{} does not exist' .format (filename ))
1974+ if getattr (ex , 'errno' , 0 ) == errno .EACCES :
1975+ raise FileOperationError (
1976+ 'Permission denied when trying to read {}. '
1977+ 'Please ensure you have read access to this file, or specify a different file path '
1978+ 'using the --file/-f argument.' .format (filename )
1979+ )
19741980 raise
19751981 except (yaml .parser .ParserError , UnicodeDecodeError ) as ex :
19761982 raise CLIError ('Error parsing {} ({})' .format (filename , str (ex )))
@@ -2019,8 +2025,15 @@ def merge_kubernetes_configurations(existing_file, addition_file, replace, conte
20192025 existing_file_perms ,
20202026 )
20212027
2022- with open (existing_file , 'w+' ) as stream :
2023- yaml .safe_dump (existing , stream , default_flow_style = False )
2028+ try :
2029+ with open (existing_file , 'w+' ) as stream :
2030+ yaml .safe_dump (existing , stream , default_flow_style = False )
2031+ except PermissionError as ex :
2032+ raise FileOperationError (
2033+ 'Permission denied when trying to write to {}. '
2034+ 'Please ensure you have write access to this file, or specify a different file path '
2035+ 'using the --file/-f argument.' .format (existing_file )
2036+ ) from ex
20242037
20252038 current_context = addition .get ('current-context' , 'UNKNOWN' )
20262039 msg = 'Merged "{}" as current context in {}' .format (
0 commit comments