From eb4d9e9f5d4d97d649462add5a86d4a0103d34cf Mon Sep 17 00:00:00 2001
From: dgelessus <dgelessus@users.noreply.github.com>
Date: Fri, 25 Aug 2023 11:23:31 +0200
Subject: [PATCH] Report CLI startup exceptions in one place where they are
 caught

The previous code expected all exceptions to be reported before they are
thrown, but not everything did that.
---
 de.prob.core/src/de/prob/cli/CliStarter.java  | 20 +++++--------------
 .../de/prob/cli/clipatterns/PortPattern.java  |  9 +--------
 .../de/prob/core/internal/AnimatorImpl.java   |  3 +--
 .../prob/core/internal/ServerConnection.java  |  3 +--
 4 files changed, 8 insertions(+), 27 deletions(-)

diff --git a/de.prob.core/src/de/prob/cli/CliStarter.java b/de.prob.core/src/de/prob/cli/CliStarter.java
index 089d9847..fe265146 100644
--- a/de.prob.core/src/de/prob/cli/CliStarter.java
+++ b/de.prob.core/src/de/prob/cli/CliStarter.java
@@ -102,10 +102,7 @@ public final class CliStarter {
 		try {
 			prologProcess = pb.start();
 		} catch (IOException e) {
-			final String message = "Problem while starting up ProB CLI. Tried to execute:"
-					+ executable;
-			Logger.notifyUser(message, e);
-			throw new CliException(message, e, true);
+			throw new CliException("Problem while starting up ProB CLI. Tried to execute:" + executable, e, false);
 		}
 
 		Assert.isNotNull(prologProcess);
@@ -144,10 +141,7 @@ public final class CliStarter {
 			} else if (os.equals(Platform.OS_LINUX)) {
 				subdir = "linux64";
 			} else {
-				final CliException cliException = new CliException(
-						"ProB does not support the plattform: " + os);
-				cliException.notifyUserOnce();
-				throw cliException;
+				throw new CliException("ProB does not support the plattform: " + os);
 			}
 
 			return new OsSpecificInfo(subdir, "probcli.sh",
@@ -187,9 +181,7 @@ public final class CliStarter {
 						|| line.contains("starting command loop"); // printed in prob_socketserver.pl
 			}
 		} catch (IOException e) {
-			final String message = "Problem while starting ProB. Cannot read from input stream.";
-			Logger.notifyUser(message, e);
-			throw new CliException(message, e, true);
+			throw new CliException("Problem while starting ProB. Cannot read from input stream.", e, true);
 		}
 		for (CliPattern<?> p : patterns) {
 			p.notFound();
@@ -228,11 +220,9 @@ public final class CliStarter {
 
 			return new File(resolvedUri);
 		} catch (URISyntaxException e) {
-			throw new CliException("Unable to construct file '"
-					+ entry.getPath() + "'");
+			throw new CliException("Unable to construct file '" + entry.getPath() + "'", e, false);
 		} catch (IOException e2) {
-			throw new CliException("Input/output error when trying t find '"
-					+ fileURL + "'");
+			throw new CliException("Input/output error when trying t find '" + fileURL + "'", e2, false);
 		}
 	}
 
diff --git a/de.prob.core/src/de/prob/cli/clipatterns/PortPattern.java b/de.prob.core/src/de/prob/cli/clipatterns/PortPattern.java
index 3878e2cb..19724b1a 100644
--- a/de.prob.core/src/de/prob/cli/clipatterns/PortPattern.java
+++ b/de.prob.core/src/de/prob/cli/clipatterns/PortPattern.java
@@ -39,14 +39,7 @@ public class PortPattern extends CliPattern<Integer> {
 
 	@Override
 	public void notFound() throws CliException {
-		// final String message = "Could not determine port of ProB server";
-		// Logger.notifyUser(message);
-		// throw new CliException(message);
-
-		CliException cliException = new CliException(
-				"Could not determine port of ProB server");
-		cliException.notifyUserOnce();
-		throw cliException;
+		throw new CliException("Could not determine port of ProB server");
 	}
 
 }
diff --git a/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java b/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java
index dff26da0..a14f54bd 100644
--- a/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java
+++ b/de.prob.core/src/de/prob/core/internal/AnimatorImpl.java
@@ -98,8 +98,7 @@ public class AnimatorImpl {
 		try {
 			connector.startup(file);
 		} catch (CliException e) {
-			// The user has been notified by the underlying implementation, so
-			// we only invalidate the connector
+			e.notifyUserOnce();
 			connector = null;
 		}
 	}
diff --git a/de.prob.core/src/de/prob/core/internal/ServerConnection.java b/de.prob.core/src/de/prob/core/internal/ServerConnection.java
index 049253f2..a9c9c43f 100644
--- a/de.prob.core/src/de/prob/core/internal/ServerConnection.java
+++ b/de.prob.core/src/de/prob/core/internal/ServerConnection.java
@@ -62,8 +62,7 @@ public class ServerConnection implements IServerConnection {
 					outputStream = null;
 				}
 			}
-			ProblemHandler.handleCliException(
-					"Opening connection to ProB server failed", e);
+			throw new CliException("Opening connection to ProB server failed", e, false);
 		}
 	}
 
-- 
GitLab