Skip to content

Commit 055e519

Browse files
author
Prabhakar Kumar
committed
Fixes bug introduced in v0.7.2 wherein matlab-proxy would crash when MATLAB is not on the path.
Introduces new error messages when MATLAB is not found on path or when specified incorrectly using the MWI_CUSTOM_MATLAB_ROOT environment variable.
1 parent 01dd376 commit 055e519

File tree

14 files changed

+296
-244
lines changed

14 files changed

+296
-244
lines changed

gui/src/components/App/App.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('App Component', () => {
151151
});
152152

153153

154-
const paragraphElements = [...container.getElementsByTagName('p')];
154+
const paragraphElements = [...container.getElementsByTagName('pre')];
155155

156156

157157
expect(
@@ -173,7 +173,7 @@ describe('App Component', () => {
173173
initialState: initialState,
174174
});
175175

176-
const paragraphElements = [...container.getElementsByTagName('p')];
176+
const paragraphElements = [...container.getElementsByTagName('pre')];
177177

178178
expect(
179179
paragraphElements.some((p) =>

gui/src/components/Error/Error.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
/* Copyright (c) 2020-2022 The MathWorks, Inc. */
1+
/* Copyright (c) 2020-2023 The MathWorks, Inc. */
22

33
#error .alert {
44
padding: 0;
55
margin-bottom: 0;
66
border-radius: 10px;
77
}
88

9-
#error .modal-body,
9+
#error .modal-body pre {
10+
background-color: hsla(0, 0%, 100%, 0);
11+
border: none;
12+
font-family: inherit;
13+
font-size: 15px;
14+
white-space: pre-wrap;
15+
}
16+
1017
#error .modal-header {
1118
padding-left: 45px;
1219
}

gui/src/components/Error/Error.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2022 The MathWorks, Inc.
1+
// Copyright (c) 2020-2023 The MathWorks, Inc.
22

33
import React from 'react';
44
import Error from './index';
@@ -22,7 +22,7 @@ describe('Error Component', () => {
2222
it('should render without crashing ', () => {
2323
const { container } = render(<Error message={message} />);
2424

25-
const paragraphs = [...container.getElementsByTagName('p')];
25+
const paragraphs = [...container.getElementsByTagName('pre')];
2626

2727
expect(paragraphs.some((p) => p.textContent === message)).toBeTruthy();
2828
});

gui/src/components/Error/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2022 The MathWorks, Inc.
1+
// Copyright (c) 2020-2023 The MathWorks, Inc.
22

33
import React from 'react';
44
import PropTypes from 'prop-types';
@@ -28,7 +28,7 @@ function Error({ message, logs, children }) {
2828
<h4 className="modal-title alert_heading">Error</h4>
2929
</div>
3030
<div className="modal-body">
31-
<p>{message}</p>
31+
<pre>{message}</pre>
3232
<Linkify>{logReport}</Linkify>
3333
{children}
3434
</div>

matlab_proxy/app.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
from matlab_proxy.util import list_servers, mwi
2020
from matlab_proxy.util.mwi import environment_variables as mwi_env
2121
from matlab_proxy.util.mwi import token_auth
22-
from matlab_proxy.util.mwi.exceptions import AppError, InvalidTokenError, LicensingError
22+
from matlab_proxy.util.mwi.exceptions import (
23+
AppError,
24+
InvalidTokenError,
25+
LicensingError,
26+
)
2327

2428
mimetypes.add_type("font/woff", ".woff")
2529
mimetypes.add_type("font/woff2", ".woff2")
@@ -109,12 +113,12 @@ async def create_status_response(app, loadUrl=None):
109113
{
110114
"matlab": {
111115
"status": await state.get_matlab_state(),
112-
"version": state.settings["matlab_version"],
116+
"version": state.settings.get("matlab_version", "Unknown"),
113117
},
114118
"licensing": marshal_licensing_info(state.licensing),
115119
"loadUrl": loadUrl,
116120
"error": marshal_error(state.error),
117-
"wsEnv": state.settings["ws_env"],
121+
"wsEnv": state.settings.get("ws_env", ""),
118122
}
119123
)
120124

@@ -160,7 +164,6 @@ async def authenticate_request(req):
160164
Returns:
161165
JSONResponse: JSONResponse object containing information about authentication status and error if any.
162166
"""
163-
state = req.app["state"]
164167
if await token_auth.authenticate_request(req):
165168
logger.debug("!!!!!! REQUEST IS AUTHORIZED !!!!")
166169
authStatus = True

matlab_proxy/app_state.py

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
from matlab_proxy.util.mwi.exceptions import (
1616
EmbeddedConnectorError,
1717
EntitlementError,
18-
InternalError,
18+
FatalError,
1919
LicensingError,
2020
MatlabError,
21-
MatlabInstallError,
2221
OnlineLicensingError,
2322
XvfbError,
2423
log_error,
@@ -70,11 +69,12 @@ def __init__(self, settings):
7069
self.logs = {
7170
"matlab": deque(maxlen=200),
7271
}
73-
self.error = None
74-
# Start in an error state if MATLAB is not present
75-
if not self.is_matlab_present():
76-
self.error = MatlabInstallError("'matlab' executable not found in PATH")
77-
logger.error("'matlab' executable not found in PATH")
72+
73+
# Initialize with the error state from the initialization of settings
74+
self.error = settings["error"]
75+
76+
if self.error is not None:
77+
self.logs["matlab"].clear()
7878
return
7979

8080
# Keep track of when the Embedded connector starts.
@@ -153,8 +153,8 @@ async def init_licensing(self):
153153
self.__delete_cached_licensing_file()
154154

155155
# NLM Connection String set in environment
156-
elif self.settings["nlm_conn_str"] is not None:
157-
nlm_licensing_str = self.settings["nlm_conn_str"]
156+
elif self.settings.get("nlm_conn_str", None) is not None:
157+
nlm_licensing_str = self.settings.get("nlm_conn_str")
158158
logger.debug(f"Found NLM:[{nlm_licensing_str}] set in environment")
159159
logger.debug(f"Using NLM string to connect ... ")
160160
self.licensing = {
@@ -395,26 +395,17 @@ def is_licensed(self):
395395
return True
396396
return False
397397

398-
def is_matlab_present(self):
399-
"""Is MATLAB install accessible?
400-
401-
Returns:
402-
Boolean: True if MATLAB is present in the system. False otherwise.
403-
"""
404-
405-
return self.settings["matlab_path"] is not None
406-
407398
async def update_entitlements(self):
408399
"""Speaks to MW and updates MHLM entitlements
409400
410401
Raises:
411-
InternalError: When licensing is None or when licensing type is not MHLM.
402+
FatalError: When licensing is None or when licensing type is not MHLM.
412403
413404
Returns:
414405
Boolean: True if update was successful
415406
"""
416407
if self.licensing is None or self.licensing["type"] != "mhlm":
417-
raise InternalError(
408+
raise FatalError(
418409
"MHLM licensing must be configured to update entitlements!"
419410
)
420411

@@ -722,26 +713,8 @@ async def start_matlab(self, restart_matlab=False):
722713
723714
Args:
724715
restart_matlab (bool, optional): Whether to restart MATLAB. Defaults to False.
725-
726-
Raises:
727-
Exception: When MATLAB is already running and restart is False.
728-
Exception: When MATLAB is not licensed.
729716
"""
730717

731-
# FIXME
732-
if await self.get_matlab_state() != "down" and restart_matlab is False:
733-
raise Exception("MATLAB already running/starting!")
734-
735-
# FIXME
736-
if not self.is_licensed():
737-
raise Exception("MATLAB is not licensed!")
738-
739-
if not self.is_matlab_present():
740-
self.error = MatlabInstallError("'matlab' executable not found in PATH")
741-
logger.error("'matlab' executable not found in PATH")
742-
self.logs["matlab"].clear()
743-
return
744-
745718
# Ensure that previous processes are stopped
746719
await self.stop_matlab()
747720

0 commit comments

Comments
 (0)