Skip to content
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 @@ -288,7 +288,17 @@ private void build_async(String platform, String sdkVersion, HttpEntity entity,
os.close();
throw new ExtenderClientException(String.format("Failed to build source: jobId - %s, traceId - %s", jobId, traceId == null ? "null" : traceId));
}
} else {
} else if (statusCode == HttpStatus.SC_NOT_IMPLEMENTED) {
String traceId = response.getFirstHeader(TRACE_ID_HEADER_NAME).getValue();
HttpEntity responseBody = response.getEntity();
String body = responseBody != null ? EntityUtils.toString(responseBody) : "(unknown)";
String error = String.format("%s (trace id - %s)", body, traceId == null ? "null" : traceId);
log(error);
OutputStream os = new FileOutputStream(log);
os.write(error.getBytes());
os.close();
throw new ExtenderClientException(error);
} else{
String result = String.format("Async build request failed with status code %d %s", statusCode, statusLine.getReasonPhrase());
log(result);
OutputStream os = new FileOutputStream(log);
Expand All @@ -297,7 +307,10 @@ private void build_async(String platform, String sdkVersion, HttpEntity entity,
os.close();
throw new ExtenderClientException("Failed to build source.");
}
} catch (Exception e) {
} catch (ExtenderClientException exc) {
throw exc;
}
catch (Exception e) {
throw new ExtenderClientException("Failed to communicate with Extender service.", e);
}
}
Expand Down
15 changes: 13 additions & 2 deletions server/src/main/java/com/defold/extender/ExtenderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ public ResponseEntity<String> handleExtenderException(ExtenderException ex) {
return new ResponseEntity<>(ex.getOutput(), headers, HttpStatus.UNPROCESSABLE_ENTITY);
}

@ExceptionHandler({PlatformNotSupportedException.class, VersionNotSupportedException.class})
public ResponseEntity<String> handleUsupportedExceptions(Exception exc) {
LOGGER.error(Markers.SERVER_ERROR, exc.getMessage(), exc);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
return new ResponseEntity<>(exc.getMessage(), headers, HttpStatus.NOT_IMPLEMENTED);
}

@ExceptionHandler(Exception.class)
public ResponseEntity<String> handleException(Exception ex) {
LOGGER.error(Markers.SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), ex);
Expand Down Expand Up @@ -216,9 +224,12 @@ public void buildEngineAsync(HttpServletRequest _request,
buildEnvDescription = ExtenderUtil.getSdksForPlatform(platform, mappings);
} catch(ExtenderException exc) {
if (instanceType.equals(InstanceType.FRONTEND_ONLY)) {
LOGGER.error("Unsupported engine version {}", sdkVersion);
LOGGER.error("Unsupported engine version '{}'", sdkVersion);
throw new VersionNotSupportedException(sdkVersion);
}
} catch (NullPointerException exc) {
LOGGER.error("Unsupported build platform '{}'", platform);
throw new PlatformNotSupportedException(platform);
}
// Build engine locally or on remote builder
if (remoteBuilderEnabled && buildEnvDescription != null && isRemotePlatform(buildEnvDescription[0], buildEnvDescription[1])) {
Expand All @@ -229,7 +240,7 @@ public void buildEngineAsync(HttpServletRequest _request,
asyncBuilder.asyncBuildEngine(metricsWriter, platform, sdkVersion, jobDirectory, uploadDirectory, buildDirectory);
} else {
// no remote builder was found and current instance can't build
LOGGER.error("Unsupported build platform {}", platform);
LOGGER.error("Unsupported build platform '{}'", platform);
throw new PlatformNotSupportedException(platform);
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/com/defold/extender/ExtenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ public static String readContentFromResource(Resource inputSource) throws IOExce

// return a list of two string: platform name like "emsdk" and platform version like "3155"
@SuppressWarnings("unchecked")
public static String[] getSdksForPlatform(String platform, JSONObject mappings) {
public static String[] getSdksForPlatform(String platform, JSONObject mappings) throws NullPointerException {
return ((List<String>) mappings.get(platform)).toArray(new String[2]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.defold.extender;

public class PlatformNotSupportedException extends ExtenderException {
private static String ERROR_MESSAGE = "Platform %s is not supported on the current server. Please, check build server address. If error will persist - create task here https://github.com/defold/extender/issues";
private static String ERROR_MESSAGE = "Platform '%s' is not supported on the current server. Please, check build server address. If error will persist - create task here https://github.com/defold/extender/issues";

public PlatformNotSupportedException(String platform) {
super(String.format(ERROR_MESSAGE, platform));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.defold.extender;

public class VersionNotSupportedException extends ExtenderException {
private static String ERROR_MESSAGE = "Engine version %s is not supported on the current server. Please, use latest stable version. https://github.com/defold/defold/releases/latest";
private static String ERROR_MESSAGE = "Engine version '%s' is not supported on the current server. Please, use latest stable version. https://github.com/defold/defold/releases/latest";

public VersionNotSupportedException(String version) {
super(String.format(ERROR_MESSAGE, version));
Expand Down
16 changes: 14 additions & 2 deletions server/src/test/java/com/defold/extender/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggingSystem;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -589,6 +588,19 @@ public void testUnsupportedVersion() throws IOException, ExtenderClientException
);

ExtenderClientException exc = assertThrows(ExtenderClientException.class, () -> doBuild(sourceFiles, configuration));
assertTrue(exc.getMessage().contains("Unsupported engine version"));
assertTrue(exc.getMessage().contains("Engine version 'non-exist' is not supported on the current server"));
}

@Test
public void testUnsupportedPlatform() throws IOException, ExtenderClientException {
TestConfiguration configuration = new TestConfiguration(new DefoldVersion("1aafd0a262ff40214ed7f51302d92fa587c607ef", new Version(1, 10, 4), new String[]{ "x86_64-platform" }) , "x86_64-platform");
List<ExtenderResource> sourceFiles = Lists.newArrayList(
new FileExtenderResource("test-data/AndroidManifest.xml", "AndroidManifest.xml"),
new FileExtenderResource("test-data/ext2/ext.manifest"),
new FileExtenderResource("test-data/ext2/src/test_ext.cpp")
);

ExtenderClientException exc = assertThrows(ExtenderClientException.class, () -> doBuild(sourceFiles, configuration));
assertTrue(exc.getMessage().contains("Platform 'x86_64-platform' is not supported on the current server"));
}
}