From a885e7d61973461c7fd254d0d4e3f955b5ea124c Mon Sep 17 00:00:00 2001
From: Paul Kaplan <pkaplan@media.mit.edu>
Date: Tue, 12 Sep 2017 10:16:26 -0400
Subject: [PATCH] Refactor error throwing

---
 src/virtual-machine.js | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/src/virtual-machine.js b/src/virtual-machine.js
index 17df958be..8bbaf7851 100644
--- a/src/virtual-machine.js
+++ b/src/virtual-machine.js
@@ -445,23 +445,17 @@ class VirtualMachine extends EventEmitter {
      */
     duplicateSprite (targetId) {
         const target = this.runtime.getTargetById(targetId);
-
-        if (target) {
-            if (!target.isSprite()) {
-                throw new Error('Cannot duplicate non-sprite targets.');
-            }
-            const sprite = target.sprite;
-            if (!sprite) {
-                throw new Error('No sprite associated with this target.');
-            }
-
-            target.duplicate().then(newTarget => {
-                this.runtime.targets.push(newTarget);
-                this.setEditingTarget(newTarget.id);
-            });
-        } else {
+        if (!target) {
             throw new Error('No target with the provided id.');
+        } else if (!target.isSprite()) {
+            throw new Error('Cannot duplicate non-sprite targets.');
+        } else if (!target.sprite) {
+            throw new Error('No sprite associated with this target.');
         }
+        target.duplicate().then(newTarget => {
+            this.runtime.targets.push(newTarget);
+            this.setEditingTarget(newTarget.id);
+        });
     }
 
     /**