Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand error handling for reading tag files #199

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,43 @@ public void setEmitSCMEvents(boolean emitSCMEvents) {
* @return - A String containing the contents of the scanned file. Returns null when
* the file cannot be found.
*/
public String readTagFile(Run r) {
public String readTagFile(Run<?, ?> r) {
String s = null;
FilePath workspace;

// Check if a tags file has been enabled before continuing
if (getTagFile() == null) {
logger.fine(String.format("No tag file defined for run '%s'", r));
return null;
}

//We need to make sure that the workspace has been created. When 'onStarted' is
//invoked, the workspace has not yet been established, so this check is necessary.
try {
Executor executor = r.getExecutor();
if(executor == null) {
logger.fine("Failed to read tag file: Executor is null");
return null;
}
workspace = executor.getCurrentWorkspace();
if (workspace == null) {
logger.fine("Failed to read tag file: Workspace is null");
return null;
}
} catch (Exception e) {
DatadogUtilities.severe(logger, e, "Failed to read tag file when gathering workspace");
return null;
}

FilePath path = new FilePath(workspace, getTagFile());
try {
//We need to make sure that the workspace has been created. When 'onStarted' is
//invoked, the workspace has not yet been established, so this check is necessary.
FilePath workspace = r.getExecutor().getCurrentWorkspace();
if (workspace != null && getTagFile() != null) {
FilePath path = new FilePath(workspace, getTagFile());
if (path.exists()) {
s = path.readToString();
}
if (path.exists()) {
s = path.readToString();
logger.info(String.format("readTagFile successfully read tag file, tag count: %d", s.split("\n").length));
} else {
DatadogUtilities.severe(logger, null, String.format("Failed to read tag file: for run '%s', tags path not found: %s", r, path));
}
} catch (IOException | InterruptedException | NullPointerException e) {
} catch (IOException | InterruptedException e) {
DatadogUtilities.severe(logger, e, "Failed to read tag file");
}
return s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static FilePath buildFilePath(final Run<?, ?> run){

final Executor executor = run.getExecutor();
if(executor == null) {
LOGGER.fine("Unable to build FilePath. Run is null");
LOGGER.fine("Unable to build FilePath. Run executor is null");
return null;
}

Expand Down