Skip to content

Commit

Permalink
Do NOT catch Exception in the plugins as it's already handled by th…
Browse files Browse the repository at this point in the history
…e FASTEN server
  • Loading branch information
mir-am committed Jun 8, 2022
1 parent 29d20b9 commit fbb6bac
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,23 @@ public void setTopics(List<String> consumeTopics) {

@Override
public void consume(String record) {
try { // Fasten error-handling guidelines
this.pluginError = null;

this.pluginError = null;
logger.info("License feeder started.");

logger.info("License feeder started.");
// Retrieving coordinates of the input record
Revision coordinates = extractMavenCoordinates(record);
logger.info("Input coordinates: " + coordinates + ".");

// Retrieving coordinates of the input record
Revision coordinates = extractMavenCoordinates(record);
logger.info("Input coordinates: " + coordinates + ".");

// Inserting detected outbound into the database
var metadataDao = new MetadataDao(dslContext);
dslContext.transaction(transaction -> {
metadataDao.setContext(DSL.using(transaction));
insertOutboundLicenses(coordinates, record, metadataDao);
insertFileLicenses(coordinates, record, metadataDao);
});

// TODO Inserting licenses in files
// Inserting detected outbound into the database
var metadataDao = new MetadataDao(dslContext);
dslContext.transaction(transaction -> {
metadataDao.setContext(DSL.using(transaction));
insertOutboundLicenses(coordinates, record, metadataDao);
insertFileLicenses(coordinates, record, metadataDao);
});

} catch (Exception e) { // Fasten error-handling guidelines
logger.error(e.getMessage(), e.getCause());
throw e;
}
// TODO Inserting licenses in files
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,24 @@ public void setTopics(List<String> consumeTopics) {

@Override
public void consume(String record) {
try { // Fasten error-handling guidelines
this.pluginError = null;

this.pluginError = null;
logger.info("License feeder started.");

logger.info("License feeder started.");
String packageName = extractPackageName(record);
String packageVersion = extractPackageVersion(record);
String sourcePath = extractSourcePath(record);

String packageName = extractPackageName(record);
String packageVersion = extractPackageVersion(record);
String sourcePath = extractSourcePath(record);
logger.info("Package name: " + packageName + ".");
logger.info("Package version: " + packageVersion + ".");

logger.info("Package name: " + packageName + ".");
logger.info("Package version: " + packageVersion + ".");

// Inserting detected outbound into the database
var metadataDao = new MetadataDao(dslContext);
dslContext.transaction(transaction -> {
metadataDao.setContext(DSL.using(transaction));
insertOutboundLicenses(packageName, packageVersion, record, metadataDao);
insertFileLicenses(packageName, packageVersion, sourcePath, record, metadataDao);
});


} catch (Exception e) { // Fasten error-handling guidelines
logger.error(e.getMessage(), e.getCause());
throw e;
}
// Inserting detected outbound into the database
var metadataDao = new MetadataDao(dslContext);
dslContext.transaction(transaction -> {
metadataDao.setContext(DSL.using(transaction));
insertOutboundLicenses(packageName, packageVersion, record, metadataDao);
insertFileLicenses(packageName, packageVersion, sourcePath, record, metadataDao);
});
}

protected String extractPackageName(String record) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,18 @@ public void setTopics(List<String> consumeTopics) {
@Override
public void consume(String record) {
setPluginError(null);
try {
statementsProcessor.setDBConnection(contexts);
statementsProcessor.setFastenApiClient(fastenApiClient);
var jsonRecord = new JSONObject(record);
var payload = findPayload(jsonRecord);
if(payload != null) {
var ecosystem = payload.getString("forge");
var packageName = getPackageName(payload);
var version = payload.getString("version");
logger.info("Processing package update for forge \"" + ecosystem + "\": " + packageName + ":" + version);
statementsProcessor.updateNewPackageVersion(ecosystem, packageName, version);
}
else {
logger.error("Could not parse payload in message: " + record);
}
}
catch (Exception e) {
var error = "Error processing package update: " + e;
logger.error(error);
throw(e);
statementsProcessor.setDBConnection(contexts);
statementsProcessor.setFastenApiClient(fastenApiClient);
var jsonRecord = new JSONObject(record);
var payload = findPayload(jsonRecord);
if (payload != null) {
var ecosystem = payload.getString("forge");
var packageName = getPackageName(payload);
var version = payload.getString("version");
logger.info("Processing package update for forge \"" + ecosystem + "\": " + packageName + ":" + version);
statementsProcessor.updateNewPackageVersion(ecosystem, packageName, version);
} else {
logger.error("Could not parse payload in message: " + record);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,9 @@ public void setTopics(List<String> consumeTopics) {
@Override
public void consume(String record) {
this.pluginError = null;
try {
var v = updateVulnerability(record);
outputPath = baseOutputPath + File.separator + v.getId() + ".json";
lastProcessedVulnerability = v;
} catch (Exception e) {
logger.error("Error processing vulnerability statement: " + e);
throw e;
}
var v = updateVulnerability(record);
outputPath = baseOutputPath + File.separator + v.getId() + ".json";
lastProcessedVulnerability = v;
}

@Override
Expand Down

0 comments on commit fbb6bac

Please sign in to comment.