[#2150] Don't let illegal file format be a silent warning

This commit is contained in:
SiboVG 2023-03-31 15:19:37 +02:00
parent 75408cd48c
commit 5e99746e71
2 changed files with 19 additions and 10 deletions

View File

@ -94,7 +94,8 @@ public class RASPMotorLoader extends AbstractMotorLoader {
// desig diam len delays prop.w tot.w manufacturer
pieces = split(line);
if (pieces.length != 7) {
throw new IOException("Illegal file format.");
throw new IOException("Illegal file format. Motor header line must contain 7 fields:<br>" +
"&nbsp designation diameter length delays propellantWeight totalWeight manufacturer");
}
designation = pieces[0];
@ -140,7 +141,8 @@ public class RASPMotorLoader extends AbstractMotorLoader {
thrust.add(Double.parseDouble(buf[1]));
} else {
throw new IOException("Illegal file format.");
throw new IOException("Illegal file format.<br>" +
"Data should only have 2 entries: a time and thrust value.");
}
}
@ -158,7 +160,8 @@ public class RASPMotorLoader extends AbstractMotorLoader {
} catch (NumberFormatException e) {
throw new IOException("Illegal file format.");
throw new IOException("Illegal file format. Could not convert value to a number.<br" +
">Verify that each number is correctly formatted.");
}

View File

@ -27,6 +27,7 @@ import net.sf.openrocket.util.Pair;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
/**
* An asynchronous database loader that loads the internal thrust curves
@ -140,21 +141,26 @@ public class MotorDatabaseLoader extends AsynchronousDatabaseLoader {
*/
private void loadFile(GeneralMotorLoader loader, Pair<File, InputStream> f) {
try {
List<ThrustCurveMotor.Builder> motors = loader.load(f.getV(), f.getU().getName());
try {
List<ThrustCurveMotor.Builder> motors = loader.load(f.getV(), f.getU().getName());
addMotorsFromBuilders(motors);
}
catch (IllegalArgumentException e) {
catch (IllegalArgumentException | IOException e) {
Translator trans = Application.getTranslator();
String fullPath = f.getU().getPath();
String message = "<html><body><p style='width: 400px;'><i>" + e.getMessage() +
"</i>.<br><br>" + MessageFormat.format( trans.get("MotorDbLoaderDlg.message1"), fullPath) +
"<br>" + trans.get("MotorDbLoaderDlg.message2") + "</p></body></html>";
JOptionPane pane = new JOptionPane(message, JOptionPane.WARNING_MESSAGE);
JDialog dialog = pane.createDialog(null, trans.get("MotorDbLoaderDlg.title"));
dialog.setModalityType(Dialog.ModalityType.MODELESS);
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane pane = new JOptionPane(message, JOptionPane.WARNING_MESSAGE);
JDialog dialog = pane.createDialog(null, trans.get("MotorDbLoaderDlg.title"));
dialog.setModalityType(Dialog.ModalityType.MODELESS);
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
}
});
}
f.getV().close();
} catch (Exception e) {