Skip to content

Commit

Permalink
Handle internal errors in scripting API and OMEdit.
Browse files Browse the repository at this point in the history
- Add internal to the ErrorLevel enumeration and fix
  CevalScript.errorLevelToValue so that it handles
  ErrorTypes.INTERNAL().
- Add handling for ErrorLevel.internal in OMEdit.
  • Loading branch information
perost committed Sep 22, 2020
1 parent a4036d5 commit 9613d0e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,7 @@ type ErrorKind = enumeration(
runtime "simulation/function runtime error",
scripting "runtime scripting /interpretation error"
);
type ErrorLevel = enumeration(notification,warning,error);
type ErrorLevel = enumeration(internal,notification,warning,error);

record ErrorMessage
SourceInfo info;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ type ErrorKind = enumeration(
runtime "simulation/function runtime error",
scripting "runtime scripting /interpretation error"
);
type ErrorLevel = enumeration(notification,warning,error);
type ErrorLevel = enumeration(internal,notification,warning,error);

record ErrorMessage
SourceInfo info;
Expand Down
7 changes: 4 additions & 3 deletions OMCompiler/Compiler/Script/CevalScript.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1924,9 +1924,10 @@ protected function errorLevelToValue
output Values.Value val;
algorithm
val := match severity
case ErrorTypes.ERROR() then makeErrorEnumLiteral("ErrorLevel","error",1);
case ErrorTypes.WARNING() then makeErrorEnumLiteral("ErrorLevel","warning",2);
case ErrorTypes.NOTIFICATION() then makeErrorEnumLiteral("ErrorLevel","notification",3);
case ErrorTypes.INTERNAL() then makeErrorEnumLiteral("ErrorLevel","internal",1);
case ErrorTypes.ERROR() then makeErrorEnumLiteral("ErrorLevel","error",2);
case ErrorTypes.WARNING() then makeErrorEnumLiteral("ErrorLevel","warning",3);
case ErrorTypes.NOTIFICATION() then makeErrorEnumLiteral("ErrorLevel","notification",4);
else
equation
print("errorLevelToValue failed\n");
Expand Down
6 changes: 6 additions & 0 deletions OMEdit/OMEditLIB/Modeling/MessagesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ void MessageWidget::addGUIMessage(MessageItem messageItem)
// set the CSS class depending on message type
QString messageCSSClass;
switch (messageItem.getErrorType()) {
case StringHandler::Internal:
messageCSSClass = "error";
break;
case StringHandler::Warning:
messageCSSClass = "warning";
break;
Expand Down Expand Up @@ -467,6 +470,9 @@ void MessagesWidget::addGUIMessage(MessageItem messageItem)
}

switch (messageItem.getErrorType()) {
case StringHandler::Internal:
mpErrorMessageWidget->addGUIMessage(messageItem);
mpAllMessageWidget->addGUIMessage(messageItem);
case StringHandler::Notification:
mpNotificationMessageWidget->addGUIMessage(messageItem);
mpAllMessageWidget->addGUIMessage(messageItem);
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Util/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ qreal Helper::shapesStrokeWidth = 2.0;
int Helper::headingFontSize = 18;
QString Helper::ModelicaSimulationOutputFormats = "mat,plt,csv";
QString Helper::clockOptions = ",RT,CYC,CPU";
QString Helper::internalLevel = ".OpenModelica.Scripting.ErrorLevel.internal";
QString Helper::notificationLevel = ".OpenModelica.Scripting.ErrorLevel.notification";
QString Helper::warningLevel = ".OpenModelica.Scripting.ErrorLevel.warning";
QString Helper::errorLevel = ".OpenModelica.Scripting.ErrorLevel.error";
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Util/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Helper : public QObject
static int headingFontSize;
static QString ModelicaSimulationOutputFormats;
static QString clockOptions;
static QString internalLevel;
static QString notificationLevel;
static QString warningLevel;
static QString errorLevel;
Expand Down
8 changes: 7 additions & 1 deletion OMEdit/OMEditLIB/Util/StringHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ QString StringHandler::getErrorKindString(OpenModelicaErrorKinds errorKind)

StringHandler::OpenModelicaErrors StringHandler::getErrorType(QString errorType)
{
if (errorType.compare(Helper::notificationLevel) == 0) {
if (errorType.compare(Helper::internalLevel) == 0) {
return StringHandler::Internal;
} else if (errorType.compare(Helper::notificationLevel) == 0) {
return StringHandler::Notification;
} else if (errorType.compare(Helper::warningLevel) == 0) {
return StringHandler::Warning;
Expand All @@ -337,6 +339,8 @@ StringHandler::OpenModelicaErrors StringHandler::getErrorType(QString errorType)
QString StringHandler::getErrorTypeDisplayString(StringHandler::OpenModelicaErrors errorType)
{
switch (errorType) {
case StringHandler::Internal:
return tr("Internal Error");
case StringHandler::Notification:
return tr("Notification");
case StringHandler::Warning:
Expand All @@ -352,6 +356,8 @@ QString StringHandler::getErrorTypeDisplayString(StringHandler::OpenModelicaErro
QString StringHandler::getErrorTypeString(StringHandler::OpenModelicaErrors errorType)
{
switch (errorType) {
case StringHandler::Internal:
return Helper::internalLevel;
case StringHandler::Warning:
return Helper::warningLevel;
case StringHandler::OMError:
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Util/StringHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class StringHandler : public QObject
enum ViewType {Icon, Diagram, ModelicaText, NoView};
enum ModelicaClasses {Model, Class, ExpandableConnector, Connector, Record, Block, Function, Package, Primitive, Type, Operator,
OperatorRecord, OperatorFunction, Optimization, Parameter, Constant, Protected, Enumeration};
enum OpenModelicaErrors {Notification, Warning, OMError, NoOMError};
enum OpenModelicaErrors {Internal, Notification, Warning, OMError, NoOMError};
enum OpenModelicaErrorKinds {Syntax, Grammar, Translation, Symbolic, Simulation, Scripting, NoOMErrorKind};
enum LinePattern {LineNone, LineSolid, LineDash, LineDot, LineDashDot, LineDashDotDot};
enum FillPattern {FillNone, FillSolid, FillHorizontal, FillVertical, FillCross, FillForward, FillBackward, FillCrossDiag,
Expand Down

0 comments on commit 9613d0e

Please sign in to comment.