Skip to content

Commit

Permalink
Show actual error message in graph viewer
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 612608425
  • Loading branch information
zzzaries authored and Copybara-Service committed Mar 4, 2024
1 parent fc3d60e commit b2c1188
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def xspace_to_tool_data(
tool: A string of tool name.
params: user input parameters.
xspace_wrapper_func: A callable that takes a list of strings and a tool and
returns the raw data.
returns the raw data. If failed, raw data contains the error message.
Returns:
Returns a string of tool data and the content type for the response.
Expand Down Expand Up @@ -152,6 +152,12 @@ def xspace_to_tool_data(
if success:
data = raw_data
content_type = 'text/html'
else:
# TODO(tf-profiler) Handle errors for other tools as well,
# to pass along the error message to client
if isinstance(raw_data, bytes):
raw_data = raw_data.decode('utf-8')
raise ValueError(raw_data)
elif tool == 'memory_viewer':
options = {'module_name': params.get('host')}
raw_data, success = xspace_wrapper_func(xspace_paths, tool, options)
Expand Down
29 changes: 23 additions & 6 deletions plugin/tensorboard_plugin_profile/profile_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def static_file_route(self, request):
try:
contents = self._read_static_file_impl(filename)
except IOError:
return respond('404 Not Found', 'text/plain', code=404)
return respond('Fail to read the files.', 'text/plain', code=404)
return respond(contents, mimetype)

@wrappers.Request.application
Expand Down Expand Up @@ -622,14 +622,23 @@ def data_impl(self, request):
except tf.errors.OpError as e:
logger.warning('Cannot read asset directory: %s, OpError %s', run_dir,
e)
raise IOError(
'Cannot read asset directory: %s, OpError %s' % (run_dir, e)
) from e
else:
asset_paths = [asset_path]

try:
data, content_type = convert.xspace_to_tool_data(
asset_paths, tool, params)
except AttributeError:
except AttributeError as e:
logger.warning('XPlane converters are available after Tensorflow 2.4')
raise AttributeError(
'XPlane converters are available after Tensorflow 2.4'
) from e
except ValueError as e:
logger.warning('XPlane convert to tool data failed as %s', e)
raise e
return data, content_type, content_encoding

raw_data = None
Expand All @@ -650,10 +659,18 @@ def data_impl(self, request):
def data_route(self, request):
# params
# request: XMLHTTPRequest.
data, content_type, content_encoding = self.data_impl(request)
if data is None:
return respond('404 Not Found', 'text/plain', code=404)
return respond(data, content_type, content_encoding=content_encoding)
try:
data, content_type, content_encoding = self.data_impl(request)
if data is None:
return respond('No Data', 'text/plain', code=404)
return respond(data, content_type, content_encoding=content_encoding)
# Data fetch error handler
except AttributeError as e:
return respond(str(e), 'text/plain', code=500)
except ValueError as e:
return respond(str(e), 'text/plain', code=500)
except IOError as e:
return respond(str(e), 'text/plain', code=500)

@wrappers.Request.application
def capture_route(self, request):
Expand Down

0 comments on commit b2c1188

Please sign in to comment.