Skip to content

Commit 3e5d0f4

Browse files
committed
Create RestApiError to stop vulnchainfinder when the REST API is unavailable
1 parent d385984 commit 3e5d0f4

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

plugins/vulnerable-chain-finder/src/main/java/eu/f4sten/vulchainfinder/Main.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import eu.f4sten.infra.kafka.MessageGenerator;
2626
import eu.f4sten.pomanalyzer.data.MavenId;
2727
import eu.f4sten.pomanalyzer.data.PomAnalysisResult;
28+
import eu.f4sten.vulchainfinder.exceptions.RestApiError;
2829
import eu.f4sten.vulchainfinder.utils.DatabaseUtils;
2930
import eu.f4sten.vulchainfinder.utils.ImpactPropagator;
3031
import eu.f4sten.vulchainfinder.utils.RestAPIDependencyResolver;
@@ -155,6 +156,9 @@ public static MavenId extractMavenIdFrom(final PomAnalysisResult pomAnalysisResu
155156
private void runOrPublishErr(final Runnable r) {
156157
try {
157158
r.run();
159+
} catch (RestApiError e) {
160+
LOG.error("Forced to stop the plug-in as the REST API is unavailable", e);
161+
throw e;
158162
} catch (Exception e) {
159163
LOG.warn("Execution failed for input: {}", curId, e);
160164

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2022 Delft University of Technology
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package eu.f4sten.vulchainfinder.exceptions;
18+
19+
/**
20+
* A custom exception for Rest API-related exception to stop the plug-in's container. This error is unrecoverable.
21+
*/
22+
public class RestApiError extends Error {
23+
public RestApiError(String errorMsg, Throwable err) {
24+
super(errorMsg, err);
25+
}
26+
}

plugins/vulnerable-chain-finder/src/main/java/eu/f4sten/vulchainfinder/utils/RestAPIDependencyResolver.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package eu.f4sten.vulchainfinder.utils;
22

33
import eu.f4sten.pomanalyzer.data.MavenId;
4+
import eu.f4sten.vulchainfinder.exceptions.RestApiError;
45
import eu.fasten.core.data.metadatadb.codegen.tables.Dependencies;
56
import eu.fasten.core.data.metadatadb.codegen.tables.PackageVersions;
67
import java.io.IOException;
@@ -81,7 +82,7 @@ public HttpResponse<String> sendOrThrow(final HttpRequest request) {
8182
exception = e;
8283
}
8384
if (exception != null || response == null || isNotOK(response)) {
84-
throw new RuntimeException("Problem requesting Rest API.", exception);
85+
throw new RestApiError("Problem requesting Rest API.", exception);
8586
}
8687

8788
return response;

0 commit comments

Comments
 (0)