Skip to content

Commit

Permalink
refact: standardize exception logging (#1147)
Browse files Browse the repository at this point in the history
* refact: standardize exception logging (remove stack trace)
* refact: standardize use of neqsim exceptions
* test: silence tests
  • Loading branch information
asmfstatoil authored Oct 26, 2024
1 parent 45e6476 commit a32566a
Show file tree
Hide file tree
Showing 68 changed files with 631 additions and 703 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package neqsim.fluidmechanics.flownode.fluidboundary.heatmasstransfercalc.nonequilibriumfluidboundary;

import Jama.Matrix;
import neqsim.fluidmechanics.flownode.FlowNodeInterface;
import neqsim.thermo.system.SystemInterface;

import Jama.Matrix;



/**
* <p>
* Abstract NonEquilibriumFluidBoundary class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public void setOnesVec(int phase) {
}
}


/**
* Getter for property hattaNumber.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public double getMeasuredValue(String measurement, String unit) {
try {
thermoOps.TPflash();
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
logger.error(ex.getMessage());
return Double.NaN;
}
// tempFluid.display();
Expand All @@ -148,7 +148,7 @@ public double getMeasuredValue(String measurement, String unit) {
try {
thermoOps.TPflash();
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
logger.error(ex.getMessage());
return Double.NaN;
}
// tempFluid.display();
Expand All @@ -166,7 +166,7 @@ public double getMeasuredValue(String measurement, String unit) {
try {
thermoOps.TPflash();
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
logger.error(ex.getMessage());
return Double.NaN;
}
// tempFluid.display();
Expand All @@ -184,7 +184,7 @@ public double getMeasuredValue(String measurement, String unit) {
try {
thermoOps.TPflash();
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
logger.error(ex.getMessage());
return Double.NaN;
}
// tempFluid.display();
Expand All @@ -203,7 +203,7 @@ public double getMeasuredValue(String measurement, String unit) {
try {
thermoOps.TPflash();
} catch (Exception ex) {
logger.error(ex.getStackTrace());
logger.error(ex.getMessage());
return Double.NaN;
}
tempFluid.initPhysicalProperties();
Expand Down Expand Up @@ -237,7 +237,7 @@ public double getMeasuredValue(String measurement, String unit) {
try {
thermoOps.TPflash();
} catch (Exception ex) {
logger.error(ex.getStackTrace());
logger.error(ex.getMessage());
return Double.NaN;
}
if (!tempFluid.hasPhaseType("gas")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ public class ValveMechanicalDesign extends MechanicalDesign {
* Constructor for ValveMechanicalDesign.
* </p>
*
* @param equipment a
* {@link neqsim.processsimulation.processequipment.ProcessEquipmentInterface}
* object
* @param equipment a {@link neqsim.processsimulation.processequipment.ProcessEquipmentInterface}
* object
*/
public ValveMechanicalDesign(ProcessEquipmentInterface equipment) {
super(equipment);
Expand All @@ -50,7 +49,8 @@ public void readDesignSpecifications() {
if (getDesignStandard().containsKey("valve design codes")) {
System.out.println("valve code standard: "
+ getDesignStandard().get("valve design codes").getStandardName());
valveCvMax = ((ValveDesignStandard) getDesignStandard().get("valve design codes")).getValveCvMax();
valveCvMax =
((ValveDesignStandard) getDesignStandard().get("valve design codes")).getValveCvMax();
} else {
System.out.println("no valve code standard specified......using default");
}
Expand Down Expand Up @@ -78,7 +78,7 @@ public void displayResults() {
Container dialogContentPane = dialog.getContentPane();
dialogContentPane.setLayout(new BorderLayout());

String[] names = { "Name", "Value", "Unit" };
String[] names = {"Name", "Value", "Unit"};

String[][] table = new String[16][3]; // createTable(getProcessEquipment().getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,8 @@ public CompressorCurve getCurveAtRefSpeed(double refSpeed) {
}
}
String msg = "Does not match any speed in the chart.";
neqsim.util.exception.InvalidInputException ex =
new neqsim.util.exception.InvalidInputException(this, "getCurveAtRefSpeed", "refSpeed",
msg);
throw new RuntimeException(ex);
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this,
"getCurveAtRefSpeed", "refSpeed", msg));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Fitting(String name) {
LtoD = (Double.parseDouble(dataSet.getString("LtoD")));
System.out.printf("LtoD " + LtoD);
} catch (Exception ex) {
logger.error("error in comp", ex);
logger.error("error in fittings");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,13 +567,14 @@ public String[][] reportResults() {
* @return a {@link java.lang.Object} object
*/
public Object getProperty(String propertyName, String unit, String phase, String component) {
throw new RuntimeException(
new neqsim.util.exception.NotImplementedException(this, "getProperty"));
// getFluid().getProperties.containsKey(propertyName)) {
// if(properties.containsKey(propertyName)) {
// }
// else

// todo: throw not implemented error
return null;
// return null;
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ public default double getFlowRate(String unit) {
*/
public StreamInterface clone(String name);


/**
* <p>
* flashStream.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ public void run(UUID id) {
try {
inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow);
inStream.getThermoSystem().init(3);
} catch (Exception e) {
logger.error(e.getMessage());
} catch (Exception ex) {
logger.error(ex.getMessage());
}
// inletStream.run(id);

Expand Down Expand Up @@ -572,15 +572,15 @@ public void runTransient(double dt, UUID id) {
inStream.getThermoSystem().setTotalNumberOfMoles(molarFlow);
inStream.getThermoSystem().init(1);
inStream.run(id);
} catch (Exception e) {
logger.error(e.getMessage());
} catch (Exception ex) {
logger.error(ex.getMessage());
}
try {
outStream.getThermoSystem().setTotalNumberOfMoles(molarFlow);
outStream.getThermoSystem().init(1);
outStream.run(id);
} catch (Exception e) {
logger.error(e.getMessage());
} catch (Exception ex) {
logger.error(ex.getMessage());
}
setCalculationIdentifier(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ public static ProcessSystem open(String filePath) {
return (ProcessSystem) objectinputstream.readObject();
// logger.info("process file open ok: " + filePath);
} catch (Exception ex) {
// logger.error(ex.toString());
logger.error(ex.getMessage(), ex);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ public StreamResponse(StreamInterface inputStream) {
Double.toString(
inputStream.getTVP(37.8, "C", neqsim.util.unit.Units.getSymbol("pressure"))),
neqsim.util.unit.Units.getSymbol("pressure")));
} catch (Exception e) {
logger.error(e.getMessage());
} catch (Exception ex) {
logger.error(ex.getMessage());
}
try {
newdata.put("RVP",
Expand All @@ -220,8 +220,8 @@ public StreamResponse(StreamInterface inputStream) {
newdata.put("relative density", new Value(
Double.toString(inputStream.getFluid().getPhase(name).getDensity("kg/m3") / 1000.0),
"-"));
} catch (Exception e) {
logger.error(e.getMessage());
} catch (Exception ex) {
logger.error(ex.getMessage());
}
} else if (name.equals("gas")) {
Standard_ISO6976 standard = inputStream.getISO6976("volume", 15.0, 15.0);
Expand Down
45 changes: 33 additions & 12 deletions src/main/java/neqsim/processsimulation/util/report/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class Report {
SystemInterface fluid = null;

/**
* <p>Constructor for Report.</p>
* <p>
* Constructor for Report.
* </p>
*
* @param process a {@link neqsim.processsimulation.processsystem.ProcessSystem} object
*/
Expand All @@ -39,7 +41,9 @@ public Report(ProcessSystem process) {
}

/**
* <p>Constructor for Report.</p>
* <p>
* Constructor for Report.
* </p>
*
* @param fluid a {@link neqsim.thermo.system.SystemInterface} object
*/
Expand All @@ -48,16 +52,21 @@ public Report(SystemInterface fluid) {
}

/**
* <p>Constructor for Report.</p>
* <p>
* Constructor for Report.
* </p>
*
* @param processEquipmentBaseClass a {@link neqsim.processsimulation.processequipment.ProcessEquipmentBaseClass} object
* @param processEquipmentBaseClass a
* {@link neqsim.processsimulation.processequipment.ProcessEquipmentBaseClass} object
*/
public Report(ProcessEquipmentBaseClass processEquipmentBaseClass) {
processEquipment = processEquipmentBaseClass;
}

/**
* <p>Constructor for Report.</p>
* <p>
* Constructor for Report.
* </p>
*
* @param processModule a {@link neqsim.processsimulation.processsystem.ProcessModule} object
*/
Expand All @@ -66,16 +75,21 @@ public Report(ProcessModule processModule) {
}

/**
* <p>Constructor for Report.</p>
* <p>
* Constructor for Report.
* </p>
*
* @param processModuleBaseClass a {@link neqsim.processsimulation.processsystem.ProcessModuleBaseClass} object
* @param processModuleBaseClass a
* {@link neqsim.processsimulation.processsystem.ProcessModuleBaseClass} object
*/
public Report(ProcessModuleBaseClass processModuleBaseClass) {
// TODO Auto-generated constructor stub
}

/**
* <p>generateJsonReport.</p>
* <p>
* generateJsonReport.
* </p>
*
* @return a {@link java.lang.String} object
*/
Expand All @@ -101,16 +115,23 @@ public String generateJsonReport() {
for (Map.Entry<String, String> entry : json_reports.entrySet()) {
// Parse each value as a separate JSON object using the static parseString method
try {
JsonObject nestedJsonObject = JsonParser.parseString(entry.getValue()).getAsJsonObject();
String s = entry.getValue();
if (s == null) {
// Not necessary to log that an entry is null
continue;
}
JsonObject nestedJsonObject = JsonParser.parseString(s).getAsJsonObject();

// Update the final JsonObject with the parsed JSON object
finalJsonObject.add(entry.getKey(), nestedJsonObject);
} catch (Exception e) {
logger.error(e.getMessage());
} catch (Exception ex) {
logger.error(ex.getMessage());
}
}

// Convert the final JsonObject to a JSON string with pretty printing
Gson prettyGson = new GsonBuilder().serializeSpecialFloatingPointValues().setPrettyPrinting().create();
Gson prettyGson =
new GsonBuilder().serializeSpecialFloatingPointValues().setPrettyPrinting().create();
return prettyGson.toJson(finalJsonObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ public double getValue(String returnParameter) {
} else if (returnParameter.equals("NM")) {
return NM;
} else {
neqsim.util.exception.InvalidInputException ex =
new neqsim.util.exception.InvalidInputException(this, "getValue", "returnParameter",
"parameter not supported");
throw new RuntimeException(ex);
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this, "getValue",
"returnParameter", "parameter not supported"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Standard_ISO6976_2016(SystemInterface thermoSystem) {
M[i] = this.thermoSystem.getPhase(0).getComponent(i).getMolarMass();
dataSet.next();
} catch (Exception er) {
logger.error(er.toString());
logger.error(er.getMessage());
}
componentsNotDefinedByStandard
.add("this.thermoSystem.getPhase(0).getComponent(i).getComponentName()");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public BaseContract(SystemInterface system) {
* @param country a {@link java.lang.String} object
*/
public BaseContract(SystemInterface system, String terminal, String country) {
int numb = 0;
// int numb = 0;
this.setContractName(contractName);
try (
neqsim.util.database.NeqSimContractDataBase database =
Expand All @@ -81,7 +81,7 @@ public BaseContract(SystemInterface system, String terminal, String country) {
database.getResultSet("SELECT * FROM gascontractspecifications WHERE TERMINAL='"
+ terminal + "'" + " AND COUNTRY='" + country + "'")) {
while (dataSet.next()) {
numb++;
// numb++;
StandardInterface method = getMethod(system, dataSet.getString("METHOD"));
double referencePressure = Double.parseDouble(dataSet.getString("ReferencePbar"));
method.setReferencePressure(referencePressure);
Expand All @@ -90,12 +90,12 @@ public BaseContract(SystemInterface system, String terminal, String country) {
dataSet.getString("TERMINAL"), Double.parseDouble(dataSet.getString("MINVALUE")),
Double.parseDouble(dataSet.getString("MAXVALUE")), dataSet.getString("UNIT"),
Double.parseDouble(dataSet.getString("ReferenceTdegC")),
Double.parseDouble(dataSet.getString("ReferenceTdegC")), referencePressure, ""));// dataSet.getString("Comments"));
Double.parseDouble(dataSet.getString("ReferenceTdegC")), referencePressure, "")); // dataSet.getString("Comments"));
// System.out.println(dataSet.getString("Comments"));
// System.out.println("specification added..." + numb);
}
} catch (Exception ex) {
logger.error("error in comp", ex);
logger.error("error in comp");
} finally {
specificationsNumber = spesifications.size();
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/neqsim/thermo/atomelement/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ public String[] getElementNames() {
*/
public double getNumberOfElements(String elementName) {
if (nameArray == null) {
neqsim.util.exception.InvalidInputException ex =
new neqsim.util.exception.InvalidInputException(this, "getNumberOfElements", elementName,
"component not in element database..");
throw new RuntimeException(ex);
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(this,
"getNumberOfElements", elementName, "component not in element database.."));
}
for (int i = 0; i < nameArray.length; i++) {
if (nameArray[i].equals(elementName)) {
Expand Down
Loading

0 comments on commit a32566a

Please sign in to comment.