Skip to content

Commit

Permalink
Backport PR #23377 on branch 6.x (PR: Improve message when a variable…
Browse files Browse the repository at this point in the history
… can't be viewed due to a missing module (Variable Explorer)) (#23584)
  • Loading branch information
meeseeksmachine authored Jan 29, 2025
1 parent 3bc6ebd commit 2a02e5e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion spyder/plugins/ipythonconsole/widgets/namespacebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from spyder_kernels.comms.commbase import CommError

# Local imports
from spyder.config.base import _
from spyder.config.base import _, is_conda_based_app

# For logging
logger = logging.getLogger(__name__)
Expand All @@ -42,6 +42,16 @@ def get_value(self, name):
reason_other = _("An unkown error occurred. Check the console because "
"its contents could have been printed there")
reason_comm = _("The comm channel is not working")
reason_missing_package_installer = _(
"The '{}' package is required to open this variable. "
"Unfortunately, it's not part of our installer, which means your "
"variable can't be displayed by Spyder."
)
reason_missing_package = _(
"The '{}' package is required to open this variable and it's not "
"installed alongside Spyder. To fix this problem, please install "
"it in the same environment that you use to run Spyder."
)
msg = _("<br><i>%s.</i><br><br><br>"
"<b>Note</b>: Please don't report this problem on Github, "
"there's nothing to do about it.")
Expand All @@ -63,6 +73,15 @@ def get_value(self, name):
raise
except CommError:
raise ValueError(msg % reason_comm)
except ModuleNotFoundError as e:
if is_conda_based_app():
raise ValueError(
msg % reason_missing_package_installer.format(e.name)
)
else:
raise ValueError(
msg % reason_missing_package.format(e.name)
)
except Exception:
raise ValueError(msg % reason_other)

Expand Down

0 comments on commit 2a02e5e

Please sign in to comment.