Skip to content

Commit

Permalink
Added original exception message to the catch handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Abarca committed Jul 4, 2024
1 parent 0f5654a commit 42fb6b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ public String getNodeList() throws IOException, AnsibleException {
proc.destroy();
}
Thread.currentThread().interrupt();
throw new AnsibleException("ERROR: Ansible Execution Interrupted.", e, AnsibleException.AnsibleFailureReason.Interrupted);
throw new AnsibleException("ERROR: Ansible Execution Interrupted: " + e.getMessage(), e, AnsibleException.AnsibleFailureReason.Interrupted);
} catch (Exception e) {
if (proc != null) {
proc.destroy();
}
throw new AnsibleException("ERROR: Ansible execution returned with non zero code.", e, AnsibleException.AnsibleFailureReason.Unknown);
throw new AnsibleException("ERROR: Ansible execution returned with non zero code: " + e.getMessage(), e, AnsibleException.AnsibleFailureReason.Unknown);
} finally {
if (proc != null) {
proc.getErrorStream().close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void configure(Properties configuration) throws ConfigurationException {
try {
sshTimeout = Integer.parseInt(str_sshTimeout);
} catch (NumberFormatException e) {
throw new ConfigurationException("Can't parse timeout value : " + e.getMessage());
throw new ConfigurationException("Can't parse timeout value : " + e.getMessage(), e);
}
}

Expand Down Expand Up @@ -247,7 +247,7 @@ public AnsibleRunner.AnsibleRunnerBuilder buildAnsibleRunner() throws ResourceMo
try {
sshPrivateKey = new String(Files.readAllBytes(Paths.get(sshPrivateKeyFile)));
} catch (IOException e) {
throw new ResourceModelSourceException("Could not read privatekey file " + sshPrivateKeyFile,e);
throw new ResourceModelSourceException("Could not read privatekey file " + sshPrivateKeyFile +": "+ e.getMessage(),e);
}
runnerBuilder.sshPrivateKey(sshPrivateKey);
}
Expand All @@ -257,7 +257,7 @@ public AnsibleRunner.AnsibleRunnerBuilder buildAnsibleRunner() throws ResourceMo
String sshPrivateKey = getStorageContentString(sshPrivateKeyPath, storageTree);
runnerBuilder.sshPrivateKey(sshPrivateKey);
} catch (ConfigurationException e) {
throw new ResourceModelSourceException("Could not read private key from storage path " + sshPrivateKeyPath,e);
throw new ResourceModelSourceException("Could not read private key from storage path " + sshPrivateKeyPath +": "+ e.getMessage(),e);
}
}

Expand All @@ -269,7 +269,7 @@ public AnsibleRunner.AnsibleRunnerBuilder buildAnsibleRunner() throws ResourceMo
String sshPassphrase = getStorageContentString(sshPassphraseStoragePath, storageTree);
runnerBuilder.sshPassphrase(sshPassphrase);
} catch (ConfigurationException e) {
throw new ResourceModelSourceException("Could not read passphrase from storage path " + sshPassphraseStoragePath,e);
throw new ResourceModelSourceException("Could not read passphrase from storage path " + sshPassphraseStoragePath +": "+ e.getMessage(),e);
}
}
}
Expand All @@ -284,7 +284,7 @@ public AnsibleRunner.AnsibleRunnerBuilder buildAnsibleRunner() throws ResourceMo
sshPassword = getStorageContentString(sshPasswordPath, storageTree);
runnerBuilder.sshUsePassword(Boolean.TRUE).sshPass(sshPassword);
} catch (ConfigurationException e) {
throw new ResourceModelSourceException("Could not read password from storage path " + sshPasswordPath,e);
throw new ResourceModelSourceException("Could not read password from storage path " + sshPasswordPath +": "+ e.getMessage(),e);
}
}
}
Expand Down Expand Up @@ -325,7 +325,7 @@ public AnsibleRunner.AnsibleRunnerBuilder buildAnsibleRunner() throws ResourceMo
becomePassword = getStorageContentString(becamePasswordStoragePath, storageTree);
runnerBuilder.becomePassword(becomePassword);
} catch (Exception e) {
throw new ResourceModelSourceException("Could not read becomePassword from storage path " + becamePasswordStoragePath,e);
throw new ResourceModelSourceException("Could not read becomePassword from storage path " + becamePasswordStoragePath +": "+ e.getMessage(),e);
}
}

Expand All @@ -341,7 +341,7 @@ public AnsibleRunner.AnsibleRunnerBuilder buildAnsibleRunner() throws ResourceMo
try {
vaultPassword = getStorageContentString(vaultPasswordPath, storageTree);
} catch (Exception e) {
throw new ResourceModelSourceException("Could not read vaultPassword " + vaultPasswordPath,e);
throw new ResourceModelSourceException("Could not read vaultPassword " + vaultPasswordPath +": "+ e.getMessage(),e);
}
runnerBuilder.vaultPass(vaultPassword);
}
Expand All @@ -351,7 +351,7 @@ public AnsibleRunner.AnsibleRunnerBuilder buildAnsibleRunner() throws ResourceMo
try {
vaultPassword = new String(Files.readAllBytes(Paths.get(vaultFile)));
} catch (IOException e) {
throw new ResourceModelSourceException("Could not read vault file " + vaultFile,e);
throw new ResourceModelSourceException("Could not read vault file " + vaultFile +": "+ e.getMessage(),e);
}
runnerBuilder.vaultPass(vaultPassword);
}
Expand Down Expand Up @@ -421,7 +421,7 @@ public void processWithGatherFacts(NodeSetImpl nodes, AnsibleRunner.AnsibleRunne
try {
runner.run();
} catch (Exception e) {
throw new ResourceModelSourceException("Failed Ansible Runner execution",e);
throw new ResourceModelSourceException("Failed Ansible Runner execution: " + e.getMessage(),e);
}

try {
Expand Down Expand Up @@ -641,7 +641,7 @@ public void processWithGatherFacts(NodeSetImpl nodes, AnsibleRunner.AnsibleRunne
directoryStream.close();
}
} catch (IOException e) {
throw new ResourceModelSourceException("Error reading facts.", e);
throw new ResourceModelSourceException("Error reading facts: " + e.getMessage(), e);
}

try {
Expand All @@ -659,7 +659,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
}
});
} catch (IOException e) {
throw new ResourceModelSourceException("Error deleting temporary directory.", e);
throw new ResourceModelSourceException("Error deleting temporary directory: " + e.getMessage(), e);
}
}

Expand Down Expand Up @@ -733,7 +733,7 @@ public String getNodesFromInventory(AnsibleRunner.AnsibleRunnerBuilder runnerBui
try {
return inventoryList.getNodeList();
} catch (IOException | AnsibleException e) {
throw new ResourceModelSourceException("Failed to get node list from ansible: ", e);
throw new ResourceModelSourceException("Failed to get node list from ansible: " + e.getMessage(), e);
}
}

Expand All @@ -750,10 +750,10 @@ private byte[] getStorageContent(String storagePath, StorageTree storageTree) th
return byteArrayOutputStream.toByteArray();
} catch (StorageException e) {
throw new ConfigurationException("Failed to read the ssh private key for " +
"storage path: " + storagePath + ": " + e.getMessage());
"storage path: " + storagePath + ": " + e.getMessage(), e);
} catch (IOException e) {
throw new ConfigurationException("Failed to read the ssh private key for " +
"storage path: " + storagePath + ": " + e.getMessage());
"storage path: " + storagePath + ": " + e.getMessage(), e);
}
}

Expand Down

0 comments on commit 42fb6b0

Please sign in to comment.