diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f72ed274..0b12e7f82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - #992: Implement automatic history purge logic - #973: Enables CORS and JWT configuration for WebApplications in module.xml +- #994: prevent crash when target namespace lacks IPM mappings ### Fixed - #1001: The `unmap` and `enable` commands will now only activate CPF merge once after all namespaces have been configured instead after every namespace diff --git a/src/cls/IPM/Main.cls b/src/cls/IPM/Main.cls index 64f7e2819..22ebba333 100644 --- a/src/cls/IPM/Main.cls +++ b/src/cls/IPM/Main.cls @@ -1128,7 +1128,11 @@ ClassMethod Namespace(ByRef pCommandInfo) [ Internal ] set name = $translate($get(pCommandInfo("parameters","name"),"*"),$char(34)) if (name'["*") { try { - set $namespace = name + if '..IsIPMEnabled(name) { + write $$$FormattedLine($$$Red,"IPM is not enabled in the "_name_" namespace.") + } else { + set $namespace = name + } } catch ex { $$$ThrowStatus($$$ERROR($$$GeneralError,"Failed to switch to namespace: " _ name)) } @@ -1151,9 +1155,17 @@ ClassMethod Namespace(ByRef pCommandInfo) [ Internal ] do ##class(%Library.Prompt).GetString(prompt, .value) quit:value="" try { - 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 for the selected "_selectedNamespace_" namespace.") + hang 0.5 + // Clear the current line and move the cursor up to remove the error message + write $$$ClearLineAndMoveUp + continue + } + set $namespace = selectedNamespace } catch e { - write $char(13),*27,"[K",*27,"[A" + write $$$ClearLineAndMoveUp continue } quit @@ -3983,7 +3995,8 @@ ClassMethod DisplayModules( if pNumbered { write $justify(i, numbersWidth - 2), ". " } - write $$$FormattedLinePadRight($$$Magenta, tNS _ "> ", nsWidth) + set ipmStatus=$select('..IsIPMEnabled(tNS):"(IPM not enabled)",1:"") + write $$$FormattedLinePadRight($$$Magenta, tNS _ "> "_ipmStatus, nsWidth) set tPrefix = $justify("", numbersWidth) _ tNS kill tModulesList merge tModulesList = pList(i, "modules") @@ -4062,6 +4075,13 @@ ClassMethod DisplayModules( } } +ClassMethod IsIPMEnabled(pNamespace As %String = {$namespace}) As %Boolean +{ + new $namespace + set $namespace = pNamespace + return $system.CLS.IsMthd("%IPM.Main", "Shell") +} + ClassMethod GetUpstreamPackageVersions(Output list) { set query = "SELECT %DLIST(Name) AS Repos FROM %IPM_Repo.Definition" diff --git a/src/inc/IPM/Formatting.inc b/src/inc/IPM/Formatting.inc index c5db27dd8..304bab007 100644 --- a/src/inc/IPM/Formatting.inc +++ b/src/inc/IPM/Formatting.inc @@ -10,6 +10,7 @@ ROUTINE %IPM.Formatting [Type=INC] /// Creates the control sequence for the formatting based on the code #define ControlSequence(%code) $Char(27)_"["_%code_"m" +#define ClearLineAndMoveUp $char(13),*27,"[K",*27,"[A" #; Codes to add to convert format types #define Reset 20