diff --git a/CHANGELOG.md b/CHANGELOG.md index f7f7f567..a44d59ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - #822: The CPF resource processor now supports system expressions and macros in CPF merge files - #578 Added functionality to record and display IPM history of install, uninstall, load, and update - #961: Adding creation of a lock file for a module by using the `-create-lockfile` flag on install. +- #994: prevent crash when target namespace lacks IPM mappings ### Changed - #316: All parameters, except developer mode, included with a `load`, `install` or `update` command will be propagated to dependencies diff --git a/src/cls/IPM/Main.cls b/src/cls/IPM/Main.cls index 8734ec9a..49b2326a 100644 --- a/src/cls/IPM/Main.cls +++ b/src/cls/IPM/Main.cls @@ -1079,7 +1079,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)) } @@ -1102,9 +1106,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 @@ -3848,7 +3860,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") @@ -3927,6 +3940,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 c5db27dd..304bab00 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