Align the unreachable devfile exception message (#615)
Add a common exception message and use it for cases when: The devfile location is unavailable. The devfile content is is not valid: e.g the response content is an html content of an scm authorisation page.pull/620/head
parent
f34e80450b
commit
5baa3a7ccf
|
|
@ -101,6 +101,15 @@ testFactoryResolverNoPatOAuth() {
|
|||
echo "[INFO] Check factory resolver for public repository with NO PAT/OAuth setup"
|
||||
testFactoryResolverResponse $1 200
|
||||
|
||||
echo "[INFO] Check factory resolver for private repository with NO PAT/OAuth setup"
|
||||
testFactoryResolverResponse $2 500
|
||||
}
|
||||
|
||||
# check that raw devfile url factory resolver returns correct value without any PAT/OAuth setup
|
||||
testFactoryResolverNoPatOAuthRaw() {
|
||||
echo "[INFO] Check factory resolver for public repository with NO PAT/OAuth setup"
|
||||
testFactoryResolverResponse $1 200
|
||||
|
||||
echo "[INFO] Check factory resolver for private repository with NO PAT/OAuth setup"
|
||||
testFactoryResolverResponse $2 400
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,7 @@ source "${SCRIPT_DIR}"/common.sh
|
|||
trap "catchFinish" EXIT SIGINT
|
||||
|
||||
setupTestEnvironment ${OCP_NON_ADMIN_USER_NAME}
|
||||
# due to the issue https://github.com/eclipse/che/issues/22469
|
||||
# testFactoryResolverNoPatOAuth ${PUBLIC_REPO_URL} ${PRIVATE_REPO_URL}
|
||||
testFactoryResolverNoPatOAuth ${PUBLIC_REPO_URL} ${PRIVATE_REPO_URL}
|
||||
testCloneGitRepoProjectShouldExists ${PUBLIC_REPO_WORKSPACE_NAME} ${PUBLIC_PROJECT_NAME} ${PUBLIC_REPO_URL} ${USER_CHE_NAMESPACE}
|
||||
deleteTestWorkspace ${PUBLIC_REPO_WORKSPACE_NAME} ${USER_CHE_NAMESPACE}
|
||||
testCloneGitRepoNoProjectExists ${PRIVATE_REPO_WORKSPACE_NAME} ${PRIVATE_PROJECT_NAME} ${PRIVATE_REPO_URL} ${USER_CHE_NAMESPACE}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ source "${SCRIPT_DIR}"/common.sh
|
|||
trap "catchFinish" EXIT SIGINT
|
||||
|
||||
setupTestEnvironment ${OCP_NON_ADMIN_USER_NAME}
|
||||
testFactoryResolverNoPatOAuth ${PUBLIC_REPO_RAW_PATH_URL} ${PRIVATE_REPO_RAW_PATH_URL}
|
||||
testFactoryResolverNoPatOAuthRaw ${PUBLIC_REPO_RAW_PATH_URL} ${PRIVATE_REPO_RAW_PATH_URL}
|
||||
|
||||
testCloneGitRepoProjectShouldExists ${PUBLIC_REPO_WORKSPACE_NAME} ${PUBLIC_PROJECT_NAME} ${PUBLIC_REPO_RAW_PATH_URL} ${USER_CHE_NAMESPACE}
|
||||
deleteTestWorkspace ${PUBLIC_REPO_WORKSPACE_NAME} ${USER_CHE_NAMESPACE}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ source "${SCRIPT_DIR}"/common.sh
|
|||
trap "catchFinish" EXIT SIGINT
|
||||
|
||||
setupTestEnvironment ${OCP_NON_ADMIN_USER_NAME}
|
||||
testFactoryResolverNoPatOAuth ${PUBLIC_REPO_RAW_PATH_URL} ${PRIVATE_REPO_RAW_PATH_URL}
|
||||
testFactoryResolverNoPatOAuthRaw ${PUBLIC_REPO_RAW_PATH_URL} ${PRIVATE_REPO_RAW_PATH_URL}
|
||||
|
||||
testCloneGitRepoNoProjectExists ${PUBLIC_REPO_WORKSPACE_NAME} ${PUBLIC_PROJECT_NAME} ${PUBLIC_REPO_RAW_PATH_URL} ${USER_CHE_NAMESPACE}
|
||||
deleteTestWorkspace ${PUBLIC_REPO_WORKSPACE_NAME} ${USER_CHE_NAMESPACE}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ source "${SCRIPT_DIR}"/common.sh
|
|||
trap "catchFinish" EXIT SIGINT
|
||||
|
||||
setupTestEnvironment ${OCP_NON_ADMIN_USER_NAME}
|
||||
testFactoryResolverNoPatOAuth ${PUBLIC_REPO_RAW_PATH_URL} ${PRIVATE_REPO_RAW_PATH_URL}
|
||||
testFactoryResolverNoPatOAuthRaw ${PUBLIC_REPO_RAW_PATH_URL} ${PRIVATE_REPO_RAW_PATH_URL}
|
||||
|
||||
testCloneGitRepoNoProjectExists ${PUBLIC_REPO_WORKSPACE_NAME} ${PUBLIC_PROJECT_NAME} ${PUBLIC_REPO_RAW_PATH_URL} ${USER_CHE_NAMESPACE}
|
||||
deleteTestWorkspace ${PUBLIC_REPO_WORKSPACE_NAME} ${USER_CHE_NAMESPACE}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ package org.eclipse.che.api.factory.server.scm;
|
|||
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static org.eclipse.che.api.factory.server.scm.PersonalAccessTokenFetcher.OAUTH_2_PREFIX;
|
||||
import static org.eclipse.che.api.factory.server.scm.exception.ExceptionMessages.getDevfileConnectionErrorMessage;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
|
@ -123,7 +124,7 @@ public class AuthorizingFileContentProvider<T extends RemoteFactoryUrl>
|
|||
}
|
||||
}
|
||||
throw new DevfileException(
|
||||
"Could not reach devfile at " + "`" + exception.getMessage() + "`", exception);
|
||||
getDevfileConnectionErrorMessage(exception.getMessage()), exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2023 Red Hat, Inc.
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* Red Hat, Inc. - initial API and implementation
|
||||
*/
|
||||
package org.eclipse.che.api.factory.server.scm.exception;
|
||||
|
||||
public class ExceptionMessages {
|
||||
public static String getDevfileConnectionErrorMessage(String location) {
|
||||
return String.format("Could not reach devfile at %s", location);
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ package org.eclipse.che.api.factory.server.urlfactory;
|
|||
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static org.eclipse.che.api.factory.server.ApiExceptionMapper.toApiException;
|
||||
import static org.eclipse.che.api.factory.server.scm.exception.ExceptionMessages.getDevfileConnectionErrorMessage;
|
||||
import static org.eclipse.che.api.factory.shared.Constants.CURRENT_VERSION;
|
||||
import static org.eclipse.che.api.workspace.server.devfile.Constants.CURRENT_API_VERSION;
|
||||
import static org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE;
|
||||
|
|
@ -130,7 +131,7 @@ public class URLFactoryBuilder {
|
|||
continue;
|
||||
} catch (DevfileException e) {
|
||||
LOG.debug("Unexpected devfile exception: {}", e.getMessage());
|
||||
throw toApiException(e, location);
|
||||
throw new ApiException(e.getMessage());
|
||||
}
|
||||
if (isNullOrEmpty(devfileYamlContent)) {
|
||||
return Optional.empty();
|
||||
|
|
@ -142,7 +143,7 @@ public class URLFactoryBuilder {
|
|||
try {
|
||||
devfileVersionDetector.devfileVersion(parsedDevfile);
|
||||
} catch (DevfileException e) {
|
||||
throw new ApiException("Failed to fetch devfile");
|
||||
throw new ApiException(getDevfileConnectionErrorMessage(devfileLocation));
|
||||
}
|
||||
return Optional.of(
|
||||
createFactory(parsedDevfile, overrideProperties, fileContentProvider, location));
|
||||
|
|
|
|||
|
|
@ -441,7 +441,8 @@ public class URLFactoryBuilderTest {
|
|||
}
|
||||
}));
|
||||
|
||||
when(fileContentProvider.fetchContent(anyString())).thenThrow(new DevfileException("", cause));
|
||||
when(fileContentProvider.fetchContent(anyString()))
|
||||
.thenThrow(new DevfileException(expectedMessage, cause));
|
||||
|
||||
// when
|
||||
try {
|
||||
|
|
@ -457,7 +458,7 @@ public class URLFactoryBuilderTest {
|
|||
|
||||
@Test(
|
||||
expectedExceptions = ApiException.class,
|
||||
expectedExceptionsMessageRegExp = "Failed to fetch devfile")
|
||||
expectedExceptionsMessageRegExp = "Could not reach devfile at location")
|
||||
public void shouldThrowErrorOnUnsupportedDevfileContent()
|
||||
throws ApiException, DevfileException, IOException {
|
||||
JsonNode jsonNode = mock(JsonNode.class);
|
||||
|
|
|
|||
Loading…
Reference in New Issue