Skip to content

Commit

Permalink
Corrected problem with initialization error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
adoble authored and adoble committed Jun 29, 2019
1 parent 7346e9a commit b9f239c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/doble/adr/ADR.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 3 additions & 11 deletions src/main/java/org/doble/commands/CommandNew.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/doble/adr/CommandNewErrorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit b9f239c

Please sign in to comment.