File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -1716,16 +1716,29 @@ def inspect_environment(
17161716 flags : list [str ] = []
17171717 if force_generate :
17181718 flags .append ("f" )
1719+
17191720 args = [python , "-m" , "rsconnect.environment" ]
1720- if len ( flags ) > 0 :
1721+ if flags :
17211722 args .append ("-" + "" .join (flags ))
17221723 args .append (directory )
17231724
17241725 try :
1725- environment_json = check_output (args , universal_newlines = True )
1726- except subprocess .CalledProcessError as e :
1727- raise RSConnectException ("Error inspecting environment: %s" % e .output )
1728- return MakeEnvironment (** json .loads (environment_json ))
1726+ environment_json = check_output (args , text = True )
1727+ except Exception as e :
1728+ raise RSConnectException ("Error inspecting environment (subprocess failed)" ) from e
1729+
1730+ try :
1731+ environment_data = json .loads (environment_json )
1732+ except json .JSONDecodeError as e :
1733+ raise RSConnectException ("Error parsing environment JSON" ) from e
1734+
1735+ try :
1736+ return MakeEnvironment (** environment_data )
1737+ except TypeError as e :
1738+ system_error_message = environment_data .get ("error" )
1739+ if system_error_message :
1740+ raise RSConnectException (f"Error creating environment: { system_error_message } " ) from e
1741+ raise RSConnectException ("Error constructing environment object" ) from e
17291742
17301743
17311744def get_python_env_info (
Original file line number Diff line number Diff line change @@ -1212,6 +1212,13 @@ def test_inspect_environment(self):
12121212 assert environment is not None
12131213 assert environment .python != ""
12141214
1215+ def test_inspect_environment_catches_type_error (self ):
1216+ with pytest .raises (RSConnectException ) as exec_info :
1217+ inspect_environment (sys .executable , None ) # type: ignore
1218+
1219+ assert isinstance (exec_info .value , RSConnectException )
1220+ assert isinstance (exec_info .value .__cause__ , TypeError )
1221+
12151222
12161223@pytest .mark .parametrize (
12171224 (
You can’t perform that action at this time.
0 commit comments