From 92da8d9eccc845761f5cf7b275b121bcb5400ae7 Mon Sep 17 00:00:00 2001
From: dgelessus <dgelessus@users.noreply.github.com>
Date: Mon, 25 Jun 2018 11:56:57 +0200
Subject: [PATCH] Show error when using :show in an uninitialised state

---
 notebooks/tests/show.ipynb                    | 52 +++++--------------
 .../prob2/jupyter/commands/ShowCommand.java   |  4 ++
 2 files changed, 16 insertions(+), 40 deletions(-)

diff --git a/notebooks/tests/show.ipynb b/notebooks/tests/show.ipynb
index 0523575..062485c 100644
--- a/notebooks/tests/show.ipynb
+++ b/notebooks/tests/show.ipynb
@@ -55,26 +55,12 @@
    "metadata": {},
    "outputs": [
     {
-     "data": {
-      "text/markdown": [
-       "<table><tbody>\n",
-       "<tr>\n",
-       "<td style=\"padding:0\">![null](null)</td>\n",
-       "<td style=\"padding:0\">![null](null)</td>\n",
-       "</tr>\n",
-       "<tr>\n",
-       "<td style=\"padding:0\">![null](null)</td>\n",
-       "<td style=\"padding:0\">![null](null)</td>\n",
-       "</tr>\n",
-       "</tbody></table>"
-      ],
-      "text/plain": [
-       "<Animation function visualisation>"
-      ]
-     },
-     "execution_count": 3,
-     "metadata": {},
-     "output_type": "execute_result"
+     "ename": "CommandExecutionException",
+     "evalue": ":show: Machine is not initialised, cannot show animation function visualisation",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[1m\u001b[31m:show: Machine is not initialised, cannot show animation function visualisation\u001b[0m"
+     ]
     }
    ],
    "source": [
@@ -107,26 +93,12 @@
    "metadata": {},
    "outputs": [
     {
-     "data": {
-      "text/markdown": [
-       "<table><tbody>\n",
-       "<tr>\n",
-       "<td style=\"padding:0\">![null](null)</td>\n",
-       "<td style=\"padding:0\">![null](null)</td>\n",
-       "</tr>\n",
-       "<tr>\n",
-       "<td style=\"padding:0\">![null](null)</td>\n",
-       "<td style=\"padding:0\">![null](null)</td>\n",
-       "</tr>\n",
-       "</tbody></table>"
-      ],
-      "text/plain": [
-       "<Animation function visualisation>"
-      ]
-     },
-     "execution_count": 5,
-     "metadata": {},
-     "output_type": "execute_result"
+     "ename": "CommandExecutionException",
+     "evalue": ":show: Machine is not initialised, cannot show animation function visualisation",
+     "output_type": "error",
+     "traceback": [
+      "\u001b[1m\u001b[31m:show: Machine is not initialised, cannot show animation function visualisation\u001b[0m"
+     ]
     }
    ],
    "source": [
diff --git a/src/main/java/de/prob2/jupyter/commands/ShowCommand.java b/src/main/java/de/prob2/jupyter/commands/ShowCommand.java
index 1b7fa92..9b84ad1 100644
--- a/src/main/java/de/prob2/jupyter/commands/ShowCommand.java
+++ b/src/main/java/de/prob2/jupyter/commands/ShowCommand.java
@@ -44,6 +44,10 @@ public final class ShowCommand implements Command {
 		
 		final Trace trace = this.animationSelector.getCurrentTrace();
 		
+		if (!trace.getCurrentState().isInitialised()) {
+			throw new UserErrorException("Machine is not initialised, cannot show animation function visualisation");
+		}
+		
 		final GetImagesForMachineCommand cmd1 = new GetImagesForMachineCommand();
 		trace.getStateSpace().execute(cmd1);
 		final Map<Integer, String> images = cmd1.getImages();
-- 
GitLab