Skip to content

Commit fa1af09

Browse files
subhamsoni-googlecopybara-github
authored andcommitted
Replace %s with %r for logging exceptions.
PiperOrigin-RevId: 834275991
1 parent 2fd3f5b commit fa1af09

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

plugin/xprof/profile_plugin.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def _get_local_file_identifier(self, file_path_str: str) -> Optional[str]:
450450
return None
451451
except OSError as e:
452452
logger.error(
453-
'OSError getting stat for local file %s: %s', file_path_str, e
453+
'OSError getting stat for local file %s: %r', file_path_str, e
454454
)
455455
return None
456456

@@ -486,7 +486,7 @@ def _get_gcs_file_hash(self, file_path_str: str) -> Optional[str]:
486486
return None
487487
except Exception as e: # pylint: disable=broad-exception-caught
488488
logger.exception(
489-
'Unexpected error getting hash for GCS path %s: %s', file_path_str, e
489+
'Unexpected error getting hash for GCS path %s: %r', file_path_str, e
490490
)
491491
return None
492492

@@ -527,7 +527,7 @@ def _get_current_xplane_file_states(self) -> Optional[Dict[str, str]]:
527527
file_identifiers[xplane_file.name] = file_id
528528
return file_identifiers
529529
except OSError as e:
530-
logger.warning('Could not glob files in %s: %s', self._profile_run_dir, e)
530+
logger.warning('Could not glob files in %s: %r', self._profile_run_dir, e)
531531
return None
532532

533533
def load(self) -> Optional[List[str]]:
@@ -544,7 +544,7 @@ def load(self) -> Optional[List[str]]:
544544
cached_data = json.load(f)
545545
except (OSError, json.JSONDecodeError) as e:
546546
logger.warning(
547-
'Error reading or decoding cache file %s: %s, invalidating.',
547+
'Error reading or decoding cache file %s: %r, invalidating.',
548548
self._cache_file,
549549
e,
550550
)
@@ -606,7 +606,7 @@ def save(self, tools: Sequence[str]) -> None:
606606
json.dump(new_cache_data, f, sort_keys=True, indent=2)
607607
logger.info('ToolsCache saved: %s', self._cache_file)
608608
except (OSError, TypeError) as e:
609-
logger.error('Error writing cache file %s: %s', self._cache_file, e)
609+
logger.error('Error writing cache file %s: %r', self._cache_file, e)
610610

611611
def invalidate(self) -> None:
612612
"""Deletes the cache file, forcing regeneration on the next load."""
@@ -616,7 +616,7 @@ def invalidate(self) -> None:
616616
except FileNotFoundError:
617617
pass
618618
except OSError as e:
619-
logger.error('Error removing cache file %s: %s', self._cache_file, e)
619+
logger.error('Error removing cache file %s: %r', self._cache_file, e)
620620

621621

622622
class _TfProfiler:
@@ -960,9 +960,9 @@ def _get_valid_hosts(
960960
if host_name:
961961
all_xplane_files[host_name] = xplane_path
962962
except OSError as e:
963-
logger.warning('Cannot read asset directory: %s, OpError %s', run_dir, e)
963+
logger.warning('Cannot read asset directory: %s, OpError %r', run_dir, e)
964964
raise IOError(
965-
'Cannot read asset directory: %s, OpError %s' % (run_dir, e)
965+
'Cannot read asset directory: %s, OpError %r' % (run_dir, e)
966966
) from e
967967

968968
if hosts_param and self._does_tool_support_multi_hosts_processing(tool):
@@ -1049,7 +1049,7 @@ def data_impl(
10491049
else:
10501050
use_saved_result = False
10511051
except OSError as e:
1052-
logger.warning('Cannot read cache version file: %s', e)
1052+
logger.warning('Cannot read cache version file: %r', e)
10531053
use_saved_result = False
10541054

10551055
graph_viewer_options = self._get_graph_viewer_options(request)
@@ -1105,15 +1105,15 @@ def data_impl(
11051105
data, content_type = convert.xspace_to_tool_data(
11061106
asset_paths, tool, params)
11071107
except AttributeError as e:
1108-
logger.warning('Error generating analysis results due to %s', e)
1108+
logger.warning('Error generating analysis results due to %r', e)
11091109
raise AttributeError(
1110-
'Error generating analysis results due to %s' % e
1110+
'Error generating analysis results due to %r' % e
11111111
) from e
11121112
except ValueError as e:
1113-
logger.warning('XPlane convert to tool data failed as %s', e)
1113+
logger.warning('XPlane convert to tool data failed as %r', e)
11141114
raise e
11151115
except FileNotFoundError as e:
1116-
logger.warning('XPlane convert to tool data failed as %s', e)
1116+
logger.warning('XPlane convert to tool data failed as %r', e)
11171117
raise e
11181118

11191119
# Write cache version file if use_saved_result is False.
@@ -1124,7 +1124,7 @@ def data_impl(
11241124
) as f:
11251125
f.write(version.__version__)
11261126
except OSError as e:
1127-
logger.warning('Cannot write cache version file: %s', e)
1127+
logger.warning('Cannot write cache version file: %r', e)
11281128

11291129
return data, content_type, content_encoding
11301130

@@ -1147,7 +1147,7 @@ def hlo_module_list_impl(
11471147
path = epath.Path(run_dir)
11481148
filenames = path.glob(tool_pattern)
11491149
except OSError as e:
1150-
logger.warning('Cannot read asset directory: %s, OpError %s', run_dir, e)
1150+
logger.warning('Cannot read asset directory: %s, OpError %r', run_dir, e)
11511151
filenames = [os.fspath(os.path.basename(f)) for f in filenames]
11521152
for filename in filenames:
11531153
module_name, _ = _parse_filename(filename)
@@ -1492,7 +1492,7 @@ def generate_tools_of_run(self, run: str) -> Iterator[str]:
14921492
all_filenames = [f.name for f in profile_run_dir.iterdir()]
14931493
except OSError as e:
14941494
logger.warning(
1495-
'Cannot read asset directory: %s, Error %s', profile_run_dir, e
1495+
'Cannot read asset directory: %s, Error %r', profile_run_dir, e
14961496
)
14971497
return tools
14981498

0 commit comments

Comments
 (0)