Skip to content

Commit

Permalink
Improve error code constants
Browse files Browse the repository at this point in the history
  • Loading branch information
rlktradewright committed Jul 14, 2023
1 parent 0376ff9 commit bd764c6
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/ibcalpha/ibc/AbstractLoginHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void initiateLogin(Window window) {
Utils.logToConsole("Login attempt: " + ++loginAttemptNumber);
doLogin(window);
} catch (IbcException e) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_CANT_FIND_CONTROL, "could not login: could not find control: " + e.getMessage());
Utils.exitWithError(ErrorCodes.CANT_FIND_CONTROL, "could not login: could not find control: " + e.getMessage());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ibcalpha/ibc/ComponentIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ComponentIterator implements Iterator<Component> {
Component mCurrent;

ComponentIterator(Container container) {
if (container == null) Utils.exitWithException(ErrorCodes.ERROR_CODE_UNHANDLED_EXCEPTION,new NullPointerException());
if (container == null) Utils.exitWithException(ErrorCodes.UNHANDLED_EXCEPTION,new NullPointerException());
mStack.push(new NodeState(container));
}

Expand Down
2 changes: 1 addition & 1 deletion src/ibcalpha/ibc/DefaultLoginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private boolean getTWSUserNameAndPasswordFromArguments(String[] args) {
for (int i = 0; i < args.length; i++) {
Utils.logRawToConsole("arg[" + i + "]=" + args[i]);
}
Utils.exitWithError(ErrorCodes.ERROR_CODE_INCORRECT_NUMBER_OF_ARGUMENTS);
Utils.exitWithError(ErrorCodes.INCORRECT_NUMBER_OF_ARGS);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ibcalpha/ibc/DefaultSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static String getSettingsPath(String [] args) {
}
File finiPath = new File(iniPath);
if (!finiPath.isFile() || !finiPath.exists()) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_INI_FILE_NOT_EXIST, "ini file \"" + iniPath +
Utils.exitWithError(ErrorCodes.INI_FILE_DOES_NOT_EXIST, "ini file \"" + iniPath +
"\" either does not exist, or is a directory. quitting...");
}
return iniPath;
Expand Down
2 changes: 1 addition & 1 deletion src/ibcalpha/ibc/DefaultTradingModeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DefaultTradingModeManager(String[] args) {

private void setTradingMode(String value) {
if (!(value.equalsIgnoreCase(TRADING_MODE_LIVE) || value.equalsIgnoreCase(TRADING_MODE_PAPER))) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_INVALID_TRADING_MODE, "Invalid Trading Mode argument or .ini file setting: " + tradingMode);
Utils.exitWithError(ErrorCodes.INVALID_TRADING_MODE, "Invalid Trading Mode argument or .ini file setting: " + tradingMode);
}
tradingMode = value;
}
Expand Down
26 changes: 13 additions & 13 deletions src/ibcalpha/ibc/ErrorCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@

public final class ErrorCodes {

public static final int ERROR_CODE_UNHANDLED_EXCEPTION = 1100;
public static final int ERROR_CODE_CANT_FIND_CONTROL = 1101;
public static final int ERROR_CODE_INCORRECT_NUMBER_OF_ARGUMENTS = 1102;
public static final int ERROR_CODE_INI_FILE_NOT_EXIST = 1103;
public static final int ERROR_CODE_INVALID_TRADING_MODE = 1104;
public static final int ERROR_CODE_INVALID_CLOSEDOWN_AT_SETTING = 1105;
public static final int ERROR_CODE_CANT_CREATE_TWS_SETTINGS_DIRECTORY = 1106;
public static final int ERROR_CODE_CANT_FIND_ENTRYPOINT = 1107;
public static final int ERROR_CODE_INVALID_JTSINI_PATH = 1108;
public static final int ERROR_CODE_IO_EXCEPTION_ON_JTSINI = 1109;
public static final int ERROR_CODE_INVALID_STATE = 1110;
public static final int ERROR_CODE_2FA_LOGIN_TIMED_OUT = 1111;
public static final int ERROR_CODE_LOGIN_DIALOG_DISPLAY_TIMEOUT = 1112;
public static final int UNHANDLED_EXCEPTION = 1100;
public static final int CANT_FIND_CONTROL = 1101;
public static final int INCORRECT_NUMBER_OF_ARGS = 1102;
public static final int INI_FILE_DOES_NOT_EXIST = 1103;
public static final int INVALID_TRADING_MODE = 1104;
public static final int INVALID_SETTING_VALUE = 1105;
public static final int CANT_CREATE_TWS_SETTINGS_DIR = 1106;
public static final int CANT_FIND_ENTRYPOINT = 1107;
public static final int INVALID_JTSINI_PATH = 1108;
public static final int IO_EXCEPTION_ON_JTSINI = 1109;
public static final int INVALID_STATE = 1110;
public static final int SECOND_FACTOR_AUTH_LOGIN_TIMED_OUT = 1111;
public static final int LOGIN_DIALOG_DISPLAY_TIMED_OUT = 1112;
}
12 changes: 6 additions & 6 deletions src/ibcalpha/ibc/IbcTws.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static void checkArguments(String[] args) {
for (String arg : args) {
Utils.logRawToConsole(arg);
}
Utils.exitWithError(ErrorCodes.ERROR_CODE_INCORRECT_NUMBER_OF_ARGUMENTS);
Utils.exitWithError(ErrorCodes.INCORRECT_NUMBER_OF_ARGS);
}
}

Expand Down Expand Up @@ -385,7 +385,7 @@ private static Date getShutdownTime() {
}
}
} catch (ParseException e) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_INVALID_CLOSEDOWN_AT_SETTING,
Utils.exitWithError(ErrorCodes.INVALID_SETTING_VALUE,
"Invalid ClosedownAt setting: '" + shutdownTimeSetting + "'; format should be: <[day ]hh:mm> eg 22:00 or Friday 22:00");
}
return cal.getTime();
Expand All @@ -401,10 +401,10 @@ private static String getTWSSettingsDirectory() {
try {
Files.createDirectories(Paths.get(path));
} catch (FileAlreadyExistsException ex) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_CANT_CREATE_TWS_SETTINGS_DIRECTORY,
Utils.exitWithError(ErrorCodes.CANT_CREATE_TWS_SETTINGS_DIR,
"Failed to create TWS settings directory at: " + path + "; a file of that name already exists");
} catch (IOException ex) {
Utils.exitWithException(ErrorCodes.ERROR_CODE_CANT_CREATE_TWS_SETTINGS_DIRECTORY, ex);
Utils.exitWithException(ErrorCodes.CANT_CREATE_TWS_SETTINGS_DIR, ex);
}
return path;
}
Expand Down Expand Up @@ -439,7 +439,7 @@ private static void startGateway() {
} catch (Throwable t) {
Utils.logError("Exception occurred at Gateway entry point: ibgateway.GWClient.main");
t.printStackTrace(Utils.getErrStream());
Utils.exitWithError(ErrorCodes.ERROR_CODE_CANT_FIND_ENTRYPOINT);
Utils.exitWithError(ErrorCodes.CANT_FIND_ENTRYPOINT);
}
}

Expand Down Expand Up @@ -472,7 +472,7 @@ private static void startTws() {
} catch (Throwable t) {
Utils.logError("Exception occurred at TWS entry point: jclient.LoginFrame.main");
t.printStackTrace(Utils.getErrStream());
Utils.exitWithError(ErrorCodes.ERROR_CODE_CANT_FIND_ENTRYPOINT);
Utils.exitWithError(ErrorCodes.CANT_FIND_ENTRYPOINT);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/ibcalpha/ibc/JtsIniManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static void reload() {
private static void loadIniFile() {
jtsIniFile = new File(jtsIniFilePath);
if (jtsIniFile.isDirectory()) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_INVALID_JTSINI_PATH,
Utils.exitWithError(ErrorCodes.INVALID_JTSINI_PATH,
jtsIniFilePath + " already exists but is a directory");
}
if (jtsIniFile.isFile()) {
Expand Down Expand Up @@ -248,7 +248,7 @@ private static List<String> getFileLines(File jtsIniFile) {
try {
linesList = Files.readAllLines(jtsIniFile.toPath());
} catch (IOException e) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_IO_EXCEPTION_ON_JTSINI,
Utils.exitWithError(ErrorCodes.IO_EXCEPTION_ON_JTSINI,
"Unexpected IOException on " + jtsIniFile + ": " + e.getMessage());
}
return linesList;
Expand All @@ -266,7 +266,7 @@ private static void createMinimalFile() {
writeIniFileLine(IBGATEWAY_SECTION_HEADER, w);
writeIniFileLine(APIONLY_SETTING_TRUE, w);
} catch (IOException e) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_IO_EXCEPTION_ON_JTSINI,
Utils.exitWithError(ErrorCodes.IO_EXCEPTION_ON_JTSINI,
"Problem creating " + jtsIniFilePath + ": " + e.getMessage());
}
}
Expand All @@ -278,7 +278,7 @@ private static void rewriteExistingFile(List<JtsIniSectionSetting> missingSettin
updateExistingSections(missingSettings, w);
updateUnprocessedSettings(getUnprocessedSettings(missingSettings), w);
} catch (IOException e){
Utils.exitWithError(ErrorCodes.ERROR_CODE_IO_EXCEPTION_ON_JTSINI,
Utils.exitWithError(ErrorCodes.IO_EXCEPTION_ON_JTSINI,
"Problem writing to " + jtsIniFilePath + ": " + e.getMessage());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ibcalpha/ibc/LoginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void restartAfterTime(final int secondsTillShutdown, final String message) {
Utils.logToConsole("Login has already completed - no need for IBC to exit");
return;
}
Utils.exitWithError(ErrorCodes.ERROR_CODE_2FA_LOGIN_TIMED_OUT, message);
Utils.exitWithError(ErrorCodes.SECOND_FACTOR_AUTH_LOGIN_TIMED_OUT, message);
});
}, secondsTillShutdown, TimeUnit.SECONDS);
} catch (Throwable e) {
Expand Down
2 changes: 1 addition & 1 deletion src/ibcalpha/ibc/RestartTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void run() {
restart();
} catch (Exception ex) {
writeNack(ex.getMessage());
Utils.exitWithException(ErrorCodes.ERROR_CODE_UNHANDLED_EXCEPTION, ex);
Utils.exitWithException(ErrorCodes.UNHANDLED_EXCEPTION, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private boolean secondFactorDeviceSelectionRequired(Window window) {
private void selectSecondFactorDevice(Window window) {
JList<?> deviceList = SwingUtils.findList(window, 0);
if (deviceList == null) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_CANT_FIND_CONTROL, "could not find second factor device list.");
Utils.exitWithError(ErrorCodes.CANT_FIND_CONTROL, "could not find second factor device list.");
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/ibcalpha/ibc/SessionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public static boolean isGateway() {

private static boolean _isFIX = false;
public static boolean isFIX() {
if (!_isSessionStarted) Utils.exitWithError(ErrorCodes.ERROR_CODE_INVALID_STATE, "isFix() called before session has started");
if (!_isSessionStarted) Utils.exitWithError(ErrorCodes.INVALID_STATE, "isFix() called before session has started");
return _isFIX;
}

private static boolean _isRestart;
static boolean isRestart() {
if (!_isSessionStarted) Utils.exitWithError(ErrorCodes.ERROR_CODE_INVALID_STATE, "isRestart() called before session has started");
if (!_isSessionStarted) Utils.exitWithError(ErrorCodes.INVALID_STATE, "isRestart() called before session has started");
return _isRestart;
}

Expand All @@ -67,7 +67,7 @@ static void startSession() {
// Login diaog has been shown - no need for IBC to exit
return;
}
Utils.exitWithError(ErrorCodes.ERROR_CODE_LOGIN_DIALOG_DISPLAY_TIMEOUT, "IBC closing after TWS/Gateway failed to display login dialog");
Utils.exitWithError(ErrorCodes.LOGIN_DIALOG_DISPLAY_TIMED_OUT, "IBC closing after TWS/Gateway failed to display login dialog");
});
}, loginDialogDisplayTimeout, TimeUnit.SECONDS);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ibcalpha/ibc/StopTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void run() {
stop();
} catch (Exception ex) {
writeNack(ex.getMessage());
Utils.exitWithException(ErrorCodes.ERROR_CODE_UNHANDLED_EXCEPTION, ex);
Utils.exitWithException(ErrorCodes.UNHANDLED_EXCEPTION, ex);
}
}

Expand All @@ -69,7 +69,7 @@ private void stop() {
}

} catch (IllegalStateException e) {
Utils.exitWithException(ErrorCodes.ERROR_CODE_UNHANDLED_EXCEPTION, e);
Utils.exitWithException(ErrorCodes.UNHANDLED_EXCEPTION, e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ibcalpha/ibc/TradingLoginHandoffDialogHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void handleWindow(Window window, int eventID) {
Utils.logError(String.format(COULD_NOT_HANDLE_MESSAGE, "the 'Disconnect Other Session' button wasn't found."));
}
} else if (setting.equalsIgnoreCase("primaryoverride")) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_INVALID_STATE, String.format(ERROR_MESSAGE, "ExistingSessionDetectedAction=primaryoverride"));
Utils.exitWithError(ErrorCodes.INVALID_STATE, String.format(ERROR_MESSAGE, "ExistingSessionDetectedAction=primaryoverride"));
} else if (setting.equalsIgnoreCase("secondary")) {
Utils.exitWithError(ErrorCodes.ERROR_CODE_INVALID_STATE, String.format(ERROR_MESSAGE, "ExistingSessionDetectedAction=secondary"));
Utils.exitWithError(ErrorCodes.INVALID_STATE, String.format(ERROR_MESSAGE, "ExistingSessionDetectedAction=secondary"));
} else if (setting.equalsIgnoreCase("manual")) {
Utils.logToConsole(String.format(INFO_MESSAGE, "user must choose whether to continue with this session"));
// nothing to do
Expand Down
4 changes: 2 additions & 2 deletions src/ibcalpha/ibc/TwsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public void eventDispatched(AWTEvent event) {

logWindowStructure(window, eventID, false);
} catch (Throwable e) {
Utils.exitWithException(ErrorCodes.ERROR_CODE_UNHANDLED_EXCEPTION, e);
Utils.exitWithException(ErrorCodes.UNHANDLED_EXCEPTION, e);
}
});
} catch (Throwable e) {
Utils.exitWithException(ErrorCodes.ERROR_CODE_UNHANDLED_EXCEPTION, e);
Utils.exitWithException(ErrorCodes.UNHANDLED_EXCEPTION, e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ibcalpha/ibc/UncaughtExceptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public final class UncaughtExceptionHandler implements Thread.UncaughtExceptionH

@Override
public void uncaughtException(Thread thread, Throwable t) {
Utils.exitWithException(ErrorCodes.ERROR_CODE_UNHANDLED_EXCEPTION, t);
Utils.exitWithException(ErrorCodes.UNHANDLED_EXCEPTION, t);
}

}

0 comments on commit bd764c6

Please sign in to comment.