Skip to content

Commit 90ae068

Browse files
authored
{Misc} Replace aliased errors with OSError (#30447)
1 parent 3ee89ce commit 90ae068

File tree

29 files changed

+42
-42
lines changed

29 files changed

+42
-42
lines changed

scripts/curl_install_pypi/install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def _backup_rc(rc_file):
204204
try:
205205
shutil.copyfile(rc_file, rc_file+'.backup')
206206
print_status("Backed up '{}' to '{}'".format(rc_file, rc_file+'.backup'))
207-
except (OSError, IOError):
207+
except OSError:
208208
pass
209209

210210

@@ -233,7 +233,7 @@ def _find_line_in_file(file_path, search_pattern):
233233
for line in search_file:
234234
if search_pattern in line:
235235
return True
236-
except (OSError, IOError):
236+
except OSError:
237237
pass
238238
return False
239239

src/azure-cli-core/azure/cli/core/_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def load(self, filename, max_age=0):
3636
self.save()
3737
with open(self.filename, 'r', encoding=self._encoding) as f:
3838
self.data = json.load(f)
39-
except (OSError, IOError, json.JSONDecodeError) as load_exception:
39+
except (OSError, json.JSONDecodeError) as load_exception:
4040
# OSError / IOError should imply file not found issues which are expected on fresh runs (e.g. on build
4141
# agents or new systems). A parse error indicates invalid/bad data in the file. We do not wish to warn
4242
# on missing files since we expect that, but do if the data isn't parsing as expected.

src/azure-cli-core/azure/cli/core/commands/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _maybe_load_file(arg):
9595
if ix == 0:
9696
try:
9797
return _load_file(poss_file)
98-
except IOError:
98+
except OSError:
9999
logger.debug("Failed to load '%s', assume not a file", arg)
100100
return arg
101101

@@ -471,7 +471,7 @@ def _put_operation():
471471
obj_path = os.path.join(obj_dir, obj_file)
472472
try:
473473
os.remove(obj_path)
474-
except (OSError, IOError): # FileNotFoundError introduced in Python 3
474+
except OSError: # FileNotFoundError introduced in Python 3
475475
pass
476476
return result
477477

src/azure-cli-core/azure/cli/core/keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def generate_ssh_keys(private_key_filepath, public_key_filepath):
4848
public_key_filepath, pub_ssh_dir)
4949

5050
return public_key
51-
except IOError as e:
51+
except OSError as e:
5252
raise CLIError(e)
5353

5454
ssh_dir = os.path.dirname(private_key_filepath)

src/azure-cli-core/azure/cli/core/tests/test_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_error_raised_when_public_key_file_exists_IOError(self):
6464
with mock.patch('azure.cli.core.keys.open') as mocked_open:
6565
# mock failed call to read
6666
mocked_f = mocked_open.return_value.__enter__.return_value
67-
mocked_f.read = mock.MagicMock(side_effect=IOError("Mocked IOError"))
67+
mocked_f.read = mock.MagicMock(side_effect=OSError("Mocked IOError"))
6868

6969
# assert that CLIError raised when generate_ssh_keys is called
7070
with self.assertRaises(CLIError):

src/azure-cli-telemetry/azure/cli/telemetry/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def main():
106106
# another upload process is running.
107107
logger.info('Lock out from note file under %s which means another process is running. Exit 0.', config_dir)
108108
sys.exit(0)
109-
except IOError as err:
109+
except OSError as err:
110110
logger.warning('Unexpected IO Error %s. Exit 1.', err)
111111
sys.exit(1)
112112
except Exception as err: # pylint: disable=broad-except

src/azure-cli-telemetry/azure/cli/telemetry/components/records_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _read_file(self, path):
5151
self._add_record(line)
5252

5353
self._logger.info("Processed file %s into %d records.", path, len(self._records))
54-
except IOError as err:
54+
except OSError as err:
5555
self._logger.warning("Fail to open file %s. Reason: %s.", path, err)
5656

5757
def _add_record(self, content_line):

src/azure-cli-telemetry/azure/cli/telemetry/components/telemetry_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ def _ensure_telemetry_log_folder(config_dir):
4545
if not os.path.isdir(ret):
4646
os.makedirs(ret)
4747
return ret
48-
except (OSError, IOError, TypeError):
48+
except (OSError, TypeError):
4949
return None

src/azure-cli-telemetry/azure/cli/telemetry/components/telemetry_note.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_last_sent(self):
4141
last_send = datetime.datetime.strptime(raw, '%Y-%m-%dT%H:%M:%S')
4242
self._logger.info("Read timestamp from the note. The last send was %s.", last_send)
4343
return last_send
44-
except (AttributeError, ValueError, IOError) as err:
44+
except (OSError, AttributeError, ValueError) as err:
4545
self._logger.warning("Fail to parse or read the timestamp '%s' in the note file. Set the last send time "
4646
"to minimal. Reason: %s", raw, err)
4747
return fallback
@@ -54,7 +54,7 @@ def update_telemetry_note(self, next_send):
5454
self.fh.write(next_send.strftime('%Y-%m-%dT%H:%M:%S'))
5555
self.fh.truncate()
5656
break
57-
except IOError:
57+
except OSError:
5858
self._logger.warning('Fail to update the note file. This is the %d try.', retry + 1)
5959
else:
6060
# TODO: how to save this?

src/azure-cli/azure/cli/command_modules/acr/helm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def acr_helm_install_cli(client_version='2.16.3', install_location=None, yes=Fal
227227

228228
if os.path.splitext(f.name)[0] in ('helm', 'tiller'):
229229
os.chmod(target_path, os.stat(target_path).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
230-
except IOError as e:
230+
except OSError as e:
231231
import traceback
232232
logger.debug(traceback.format_exc())
233233
raise CLIError('Error while installing {} to {}: {}'.format(cli, install_dir, e))

0 commit comments

Comments
 (0)