From b9f239caa5e1a031e404d81ebf885870ae94b2e4 Mon Sep 17 00:00:00 2001 From: adoble Date: Sat, 29 Jun 2019 13:45:04 +0200 Subject: [PATCH] Corrected problem with initialization error handling --- src/main/java/org/doble/adr/ADR.java | 3 ++- src/main/java/org/doble/commands/CommandNew.java | 14 +++----------- .../java/org/doble/adr/CommandNewErrorTest.java | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/doble/adr/ADR.java b/src/main/java/org/doble/adr/ADR.java index 0d27705..c79d29d 100644 --- a/src/main/java/org/doble/adr/ADR.java +++ b/src/main/java/org/doble/adr/ADR.java @@ -136,8 +136,9 @@ static public Path getRootPath(Environment env) throws ADRException { if (!rootPath.isPresent()) { - String msg = "FATAL: The .adr directory cannot be found in this or parent directories.\n" + String msg = "ERROR: The .adr directory cannot be found in this or parent directories.\n" + "Has the command adr init been run?"; + env.err.println(msg); throw new ADRException(msg); } diff --git a/src/main/java/org/doble/commands/CommandNew.java b/src/main/java/org/doble/commands/CommandNew.java index 58838e5..1256963 100644 --- a/src/main/java/org/doble/commands/CommandNew.java +++ b/src/main/java/org/doble/commands/CommandNew.java @@ -81,17 +81,10 @@ public Integer call() throws Exception { env = commandADR.getEnvironment(); - // Check that the directory has been initialized, i.e. the .adr directory has been created. - // (assuming that the proerties file has then been created). - Path dotADRPath = env.dir.resolve(".adr"); - if (Files.notExists(dotADRPath)) { - String msg = "ERROR: The directory has not been initialised. Run \n" - + " adr init\n"; - env.err.println(msg); - return CommandLine.ExitCode.USAGE; - } - + // Determine where the .adr directory is stored, i.e. the root path. + // If the directory has not been initialized, this will throw an exception + Path rootPath = ADR.getRootPath(env); // Load the properties properties = new ADRProperties(env); @@ -100,7 +93,6 @@ public Integer call() throws Exception { // Determine where the ADRs are stored and // set up the record object - Path rootPath = ADR.getRootPath(env); Path docsPath = rootPath.resolve(properties.getProperty("docPath")); // Check to see if the editor command has been set. diff --git a/src/test/java/org/doble/adr/CommandNewErrorTest.java b/src/test/java/org/doble/adr/CommandNewErrorTest.java index f4246ef..7687cc4 100644 --- a/src/test/java/org/doble/adr/CommandNewErrorTest.java +++ b/src/test/java/org/doble/adr/CommandNewErrorTest.java @@ -63,7 +63,7 @@ public void testNoInit() { int exitCode = ADR.run(args, env); // Usage error - assertEquals(64, exitCode); + assertEquals(70, exitCode); // Now check if a message has been given String commandErrorOutput = new String(errorBAOS.toByteArray());