Skip to content

Commit 936e533

Browse files
mir-amproksch
authored andcommitted
Create RestApiError to stop vulnchainfinder when the REST API is unavailable
1 parent 700a8d2 commit 936e533

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
@@ -24,6 +24,7 @@
2424
import eu.f4sten.infra.kafka.Message;
2525
import eu.f4sten.infra.kafka.MessageGenerator;
2626
import eu.f4sten.pomanalyzer.data.MavenId;
27+
import eu.f4sten.vulchainfinder.exceptions.RestApiError;
2728
import eu.f4sten.vulchainfinder.utils.DatabaseUtils;
2829
import eu.f4sten.vulchainfinder.utils.ImpactPropagator;
2930
import eu.f4sten.vulchainfinder.utils.RestAPIDependencyResolver;
@@ -151,6 +152,9 @@ public static MavenId extractMavenIdFrom(final Pom pom) {
151152
private void runOrPublishErr(final Runnable r) {
152153
try {
153154
r.run();
155+
} catch (RestApiError e) {
156+
LOG.error("Forced to stop the plug-in as the REST API is unavailable", e);
157+
throw e;
154158
} catch (Exception e) {
155159
LOG.warn("Execution failed for input: {}", curId, e);
156160

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;
@@ -83,7 +84,7 @@ public HttpResponse<String> sendOrThrow(final HttpRequest request) {
8384
exception = e;
8485
}
8586
if (exception != null || response == null || isNotOK(response)) {
86-
throw new RuntimeException("Problem requesting Rest API.", exception);
87+
throw new RestApiError("Problem requesting Rest API.", exception);
8788
}
8889

8990
return response;

0 commit comments

Comments
 (0)