Skip to content

Conversation

@AshokThangavel
Copy link
Contributor

This PR resolves a terminal crash occurring within the zn (namespace) command utility. The error was triggered when the utility attempted to list or switch to namespaces where the IPM/ZPM package classes were not mapped or enabled.

The crash happened specifically because the zn tool's display logic attempted to pull UI configuration

Related Issues

Changes

  • Namespace-Aware Checks: Implemented a safety check (IsIPMEnabled) to verify if IPM classes are available in a target namespace before attempting to access them.
  • Informative Listing: Enhanced the zn * and zn [pattern] output to explicitly mark namespaces that do not have IPM enabled with a (IPM not enabled) label. This improves the user experience by clarifying why certain IPM features might be unavailable after switching.

Testing Conducted

  • Listing: Ran zn * and verified that namespaces like %SYS and USER are listed with the (IPM not enabled) suffix without throwing an error.
  • Switching: Executed zn %SYS from the IPM shell. Verified that the switch completes and the prompt handles the missing class context correctly.
  • Wildcard Filtering: Verified that pattern matching (e.g., zn %S*) still works and filters the list as expected without crashing.

Copy link
Collaborator

@isc-kiyer isc-kiyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AshokThangavel few small comments but fix looks good!

try {
set $namespace = name
if '..IsIPMEnabled(name) {
write $$$FormattedLine($$$Red," IPM is not enabled in this namespace.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include name in the message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included the name in the message!

set $namespace = $select($data(list(value), ns): $listget(ns), 1: value)
set selectedNamespace = $select($data(list(value), ns): $listget(ns), 1: value)
if '..IsIPMEnabled(selectedNamespace) {
write $$$FormattedLine($$$Red," IPM is not enabled in this namespace.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: include name in message. Also, is the space before the word "IPM" intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feed back!.

Yes, the space before “IPM” is intentional. The message is displayed on the same line after the namespace selection. Without the space, it would appear as:

Enter number or name where to go: 1IPM is not enabled in this %SYS namespace.

By adding the space, the message is displayed clearly as:

Enter number or name where to go: 1 IPM is not enabled in this %SYS namespace.

set selectedNamespace = $select($data(list(value), ns): $listget(ns), 1: value)
if '..IsIPMEnabled(selectedNamespace) {
write $$$FormattedLine($$$Red," IPM is not enabled in this namespace.")
hang 0.5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the hang? Its generally not great practice to have hangs (exceptions are for polling purposes)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @isc-kiyer
The purpose of the hang is to ensure the error message is visible to the user. Without the hang, the message IPM is not enabled in this namespace disappears immediately. Adding a 0.5-second hang allows the message to be displayed long enough for the user to notice and read it.

if '..IsIPMEnabled(selectedNamespace) {
write $$$FormattedLine($$$Red," IPM is not enabled in this namespace.")
hang 0.5
write $char(13),*27,"[K",*27,"[A"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment if writing out unicode chars. We have the $$$FormattedLine and other macros that add semantic meaning to the chars so see if any of those suffice/add to them (I notice the same pattern is used below so worth fixing it there too)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Unicode escape sequences are used to clear the current line after displaying the error message. Without clearing the line, the message would be repeatedly printed below the prompt, resulting in output such as:

Enter number or name where to go: 1 IPM is not enabled in this %SYS namespace.
Enter number or name where to go: 1 IPM is not enabled in this %SYS namespace.

Since there were no existing macros for clearing the current line, I created a macro ($$$ClearLineAndMoveUp) to encapsulate this behavior. This adds semantic meaning to the escape sequences

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<CLASS DOES NOT EXIST> error in zn command when IPM is not enabled in target namespace

2 participants