Skip to content

Commit 461fe99

Browse files
shrutipatel31facebook-github-bot
authored andcommitted
Include exception message in ErrorAnalysisCard subtitle (#4982)
Summary: Currently, the subtitle only shows a generic message like "AnalysisNotApplicableStateError encountered while computing ParallelCoordinatesPlot." Show the actual exception message, such as "AnalysisNotApplicableStateError: Experiment has no trials", providing immediate context. The exception message can now be displayed in the ErrorAnalysisCard subtitle, allowing users to immediately see the reasoning (e.g., why an analysis is not applicable). Differential Revision: D94617700
1 parent 1054802 commit 461fe99

3 files changed

Lines changed: 48 additions & 6 deletions

File tree

ax/analysis/analysis.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,18 @@ def error_card_from_analysis_e(
206206
analysis_name = analysis_e.analysis.__class__.__name__
207207
exception_name = analysis_e.exception.__class__.__name__
208208

209+
# Include the exception message in the subtitle if available, so users can
210+
# see the reasoning in the error card.
211+
subtitle = (
212+
f"{exception_name}: {exception_message}"
213+
if (exception_message := str(analysis_e.exception))
214+
else f"{exception_name} encountered while computing {analysis_name}."
215+
)
216+
209217
return ErrorAnalysisCard(
210218
name=analysis_name,
211219
title=f"{analysis_name} Error",
212-
subtitle=f"{exception_name} encountered while computing {analysis_name}.",
220+
subtitle=subtitle,
213221
df=pd.DataFrame(),
214222
blob=analysis_e.tb_str() or "",
215223
)

ax/analysis/tests/test_analysis.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-strict
7+
8+
from ax.analysis.analysis import AnalysisE, error_card_from_analysis_e
9+
from ax.analysis.plotly.parallel_coordinates import ParallelCoordinatesPlot
10+
from ax.utils.common.testutils import TestCase
11+
12+
13+
class AnalysisTest(TestCase):
14+
def test_error_card_subtitle(self) -> None:
15+
for exception, expected_subtitle in (
16+
(
17+
ValueError("something went wrong"),
18+
"ValueError: something went wrong",
19+
),
20+
(
21+
ValueError(),
22+
"ValueError encountered while computing ParallelCoordinatesPlot.",
23+
),
24+
):
25+
with self.subTest(exception=exception):
26+
analysis_e = AnalysisE(
27+
message="test",
28+
exception=exception,
29+
analysis=ParallelCoordinatesPlot(),
30+
)
31+
32+
card = error_card_from_analysis_e(analysis_e)
33+
34+
self.assertEqual(card.name, "ParallelCoordinatesPlot")
35+
self.assertEqual(card.title, "ParallelCoordinatesPlot Error")
36+
self.assertEqual(card.subtitle, expected_subtitle)

ax/api/tests/test_client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from ax.api.protocols.metric import IMetric
2424
from ax.api.protocols.runner import IRunner
2525
from ax.api.types import TParameterization
26-
from ax.core.analysis_card import AnalysisCard
2726
from ax.core.data import Data
2827
from ax.core.experiment import Experiment
2928
from ax.core.map_metric import MapMetric
@@ -1278,14 +1277,13 @@ def test_compute_analyses(self) -> None:
12781277
self.assertEqual(len(cards), 1)
12791278
self.assertEqual(cards[0].name, "ParallelCoordinatesPlot")
12801279
self.assertEqual(cards[0].title, "ParallelCoordinatesPlot Error")
1281-
self.assertEqual(
1280+
self.assertIn(
1281+
"AnalysisNotApplicableStateError",
12821282
cards[0].subtitle,
1283-
"AnalysisNotApplicableStateError encountered while computing "
1284-
"ParallelCoordinatesPlot.",
12851283
)
12861284
self.assertIn(
12871285
"Experiment has no trials",
1288-
assert_is_instance(cards[0], AnalysisCard).blob,
1286+
cards[0].subtitle,
12891287
)
12901288

12911289
for trial_index, _ in client.get_next_trials(max_trials=1).items():

0 commit comments

Comments
 (0)