From d7233208f1b78ee5da23e5bcb234a369ab7bbc29 Mon Sep 17 00:00:00 2001 From: munja Date: Mon, 21 Mar 2022 16:07:27 +0000 Subject: [PATCH] fix: enabling more descriptive mm_assignlib abort messages when library cannot be assigned --- all.sas | 53 +++++++++++++++++++++++++++--------------- base/mp_abort.sas | 6 +++-- meta/mm_assignlib.sas | 47 +++++++++++++++++++++++-------------- sasjs/sasjsconfig.json | 12 ++++++---- 4 files changed, 75 insertions(+), 43 deletions(-) diff --git a/all.sas b/all.sas index 6b51afd..371a2d2 100644 --- a/all.sas +++ b/all.sas @@ -2194,7 +2194,7 @@ Usage: %end; /* Stored Process Server web app context */ - %if %symexist(_metaport) + %if %symexist(_METAFOLDER) or "&SYSPROCESSNAME "="Compute Server " or &mode=INCLUDE %then %do; @@ -2270,12 +2270,14 @@ Usage: /* send response in SASjs JSON format */ data _null_; file _webout mod lrecl=32000 encoding='utf-8'; - length msg $32767 ; + length msg syswarningtext syserrortext $32767 ; sasdatetime=datetime(); msg=symget('msg'); %if &logline>0 %then %do; msg=cats(msg,'\n\nLog Extract:\n',symget('logmsg')); %end; + /* escape the escapes */ + msg=tranwrd(msg,'\','\\'); /* escape the quotes */ msg=tranwrd(msg,'"','\"'); /* ditch the CRLFs as chrome complains */ @@ -13358,8 +13360,8 @@ run;

SAS Macros

@li mp_abort.sas - @param libref the libref (not name) of the metadata library - @param mAbort= If not assigned, HARD will call %mp_abort(), SOFT will + @param [in] libref The libref (not name) of the metadata library + @param [in] mAbort= If not assigned, HARD will call %mp_abort(), SOFT will silently return @returns libname statement @@ -13373,11 +13375,11 @@ run; libref ,mAbort=HARD )/*/STORE SOURCE*/; - +%local mp_abort msg; +%let mp_abort=0; %if %sysfunc(libref(&libref)) %then %do; - %local mp_abort msg; %let mp_abort=0; data _null_; - length liburi LibName $200; + length liburi LibName msg $200; call missing(of _all_); nobj=metadata_getnobj("omsobj:SASLibrary?@Libref='&libref'",1,liburi); if nobj=1 then do; @@ -13391,7 +13393,24 @@ run; * not always helpful though. One example, previously received: * NOTE: Libref XX refers to the same library metadata as libref XX. */ - call symputx('msg',sysmsg(),'l'); + msg=sysmsg(); + if msg=:'ERROR: Libref SAVE is not assigned.' then do; + msg=catx(" ", + "Could not assign %upcase(&libref).", + "Please check metadata permissions! Libname:",libname, + "Liburi:",liburi + ); + end; + else if msg="ERROR: User does not have appropriate authorization "!! + "level for library SAVE." + then do; + msg=catx(" ", + "ERROR: User does not have appropriate authorization level", + "for library %upcase(&libref), libname:",libname, + "Liburi:",liburi + ); + end; + call symputx('msg',msg,'l'); if "&mabort"='HARD' then call symputx('mp_abort',1,'l'); end; else do; @@ -13410,22 +13429,18 @@ run; end; run; - %if &mp_abort=1 %then %do; - %mp_abort(iftrue= (&mp_abort=1) - ,mac=mm_assignlib.sas - ,msg=&msg - ) - %return; - %end; - %else %if %length(&msg)>2 %then %do; - %put NOTE: &msg; - %return; - %end; + %put NOTE: &msg; %end; %else %do; %put NOTE: Library &libref is already assigned; %end; + +%mp_abort(iftrue= (&mp_abort=1) + ,mac=mm_assignlib.sas + ,msg=%superq(msg) +) + %mend mm_assignlib; /** @file diff --git a/base/mp_abort.sas b/base/mp_abort.sas index 745d952..ff8926d 100644 --- a/base/mp_abort.sas +++ b/base/mp_abort.sas @@ -85,7 +85,7 @@ %end; /* Stored Process Server web app context */ - %if %symexist(_metaport) + %if %symexist(_METAFOLDER) or "&SYSPROCESSNAME "="Compute Server " or &mode=INCLUDE %then %do; @@ -161,12 +161,14 @@ /* send response in SASjs JSON format */ data _null_; file _webout mod lrecl=32000 encoding='utf-8'; - length msg $32767 ; + length msg syswarningtext syserrortext $32767 ; sasdatetime=datetime(); msg=symget('msg'); %if &logline>0 %then %do; msg=cats(msg,'\n\nLog Extract:\n',symget('logmsg')); %end; + /* escape the escapes */ + msg=tranwrd(msg,'\','\\'); /* escape the quotes */ msg=tranwrd(msg,'"','\"'); /* ditch the CRLFs as chrome complains */ diff --git a/meta/mm_assignlib.sas b/meta/mm_assignlib.sas index 68698aa..1dd3c03 100755 --- a/meta/mm_assignlib.sas +++ b/meta/mm_assignlib.sas @@ -13,8 +13,8 @@

SAS Macros

@li mp_abort.sas - @param libref the libref (not name) of the metadata library - @param mAbort= If not assigned, HARD will call %mp_abort(), SOFT will + @param [in] libref The libref (not name) of the metadata library + @param [in] mAbort= If not assigned, HARD will call %mp_abort(), SOFT will silently return @returns libname statement @@ -28,11 +28,11 @@ libref ,mAbort=HARD )/*/STORE SOURCE*/; - +%local mp_abort msg; +%let mp_abort=0; %if %sysfunc(libref(&libref)) %then %do; - %local mp_abort msg; %let mp_abort=0; data _null_; - length liburi LibName $200; + length liburi LibName msg $200; call missing(of _all_); nobj=metadata_getnobj("omsobj:SASLibrary?@Libref='&libref'",1,liburi); if nobj=1 then do; @@ -46,7 +46,24 @@ * not always helpful though. One example, previously received: * NOTE: Libref XX refers to the same library metadata as libref XX. */ - call symputx('msg',sysmsg(),'l'); + msg=sysmsg(); + if msg=:'ERROR: Libref SAVE is not assigned.' then do; + msg=catx(" ", + "Could not assign %upcase(&libref).", + "Please check metadata permissions! Libname:",libname, + "Liburi:",liburi + ); + end; + else if msg="ERROR: User does not have appropriate authorization "!! + "level for library SAVE." + then do; + msg=catx(" ", + "ERROR: User does not have appropriate authorization level", + "for library %upcase(&libref), libname:",libname, + "Liburi:",liburi + ); + end; + call symputx('msg',msg,'l'); if "&mabort"='HARD' then call symputx('mp_abort',1,'l'); end; else do; @@ -65,20 +82,16 @@ end; run; - %if &mp_abort=1 %then %do; - %mp_abort(iftrue= (&mp_abort=1) - ,mac=mm_assignlib.sas - ,msg=&msg - ) - %return; - %end; - %else %if %length(&msg)>2 %then %do; - %put NOTE: &msg; - %return; - %end; + %put NOTE: &msg; %end; %else %do; %put NOTE: Library &libref is already assigned; %end; + +%mp_abort(iftrue= (&mp_abort=1) + ,mac=mm_assignlib.sas + ,msg=%superq(msg) +) + %mend mm_assignlib; diff --git a/sasjs/sasjsconfig.json b/sasjs/sasjsconfig.json index 780bd1f..a02229f 100644 --- a/sasjs/sasjsconfig.json +++ b/sasjs/sasjsconfig.json @@ -4,11 +4,8 @@ "base", "ddl", "fcmp", - "meta", - "metax", - "server", - "viya", "lua", + "server", "tests/crossplatform", "tests/ddl" ], @@ -39,6 +36,7 @@ }, "appLoc": "/Public/temp/macrocore", "macroFolders": [ + "viya", "tests/viyaonly" ], "programFolders": [], @@ -58,6 +56,8 @@ }, "appLoc": "/Shared Data/temp/macrocore", "macroFolders": [ + "meta", + "metax", "tests/sas9only" ], "programFolders": [], @@ -78,6 +78,7 @@ }, "appLoc": "/sasjs/core", "macroFolders": [ + "server", "tests/serveronly" ], "programFolders": [], @@ -102,6 +103,7 @@ "serverType": "SASVIYA", "appLoc": "/Public/temp/macrocore", "macroFolders": [ + "viya", "tests/viyaonly" ], "deployConfig": { @@ -110,4 +112,4 @@ "contextName": "SAS Job Execution compute context" } ] -} \ No newline at end of file +}