Skip to content

Commit

Permalink
updating error codes for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Borges committed Nov 25, 2024
1 parent b0ed4ef commit 48738b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ public enum LspError {
INVALID_REMOTE_SERVER("Invalid Remote Server"),
INVALID_CACHE_SERVER("Invalid Cache Server"),
MANIFEST_FETCH_ERROR("Error fetching manifest"),
MANIFEST_REMOTE_FETCH_ERROR("Error fetching manifest from remote location"),
SERVER_FETCH_ERROR("Error fetching server"),
UNEXPECTED_CACHE_ERROR("Error while caching file"),
UNEXPECTED_MANIFEST_CACHE_ERROR("Error while caching Manifest file"),
NO_COMPATIBLE_LSP("No LSP version found matching requirements"),
NO_VALID_SERVER_FALLBACK("No valid server version to fallback to."),
ARTIFACT_VALIDATION_ERROR("Error validating artifact"),
INVALID_LAUNCH_PROPERTIES("Invalid launch properties"),
INVALID_WORKING_DIRECTORY("Invalid working directory"),
EXTRACTION_ERROR("Error or invalid zip files"),
SERVER_ZIP_EXTRACTION_ERROR("Error extracting server zip files"),
UNKNOWN("Unknown");

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public LspFetchResult fetch(final PluginPlatform platform, final PluginArchitect
}

String failureReason = "Unable to find a compatible version of Amazon Q Language Server.";
setErrorReason(LspError.NO_COMPATIBLE_LSP.toString());
setErrorReason(LspError.NO_VALID_SERVER_FALLBACK.toString());
emitGetServer(Result.FAILED, null, LanguageServerLocation.UNKNOWN, start);
throw new AmazonQPluginException(failureReason);
}
Expand Down Expand Up @@ -260,12 +260,14 @@ private boolean downloadContentFromRemote(final Content content, final Path down
return true;
} else {
ArtifactUtils.deleteDirectory(tempFolder);
setErrorReason(LspError.ARTIFACT_VALIDATION_ERROR.toString());
}
} else {
setErrorReason(LspError.SERVER_FETCH_ERROR + "-" + response.statusCode());
throw new AmazonQPluginException("Failed to download remote LSP artifact. Response code: " + response.statusCode());
}
} catch (Exception ex) {
//TODO: account for these failures in telemtry emissions
Activator.getLogger().error("Error downloading from remote", ex);
}
return false;
Expand All @@ -283,7 +285,7 @@ private boolean extractZipFilesFromRemote(final Path downloadDirectory) {
} catch (Exception e) {
String errorMessage = String.format("Failed to extract zip files in %s", downloadDirectory);
Activator.getLogger().error(errorMessage, e);
setErrorReason(LspError.EXTRACTION_ERROR.toString());
setErrorReason(LspError.SERVER_ZIP_EXTRACTION_ERROR.toString());
return false;
}
}
Expand All @@ -298,7 +300,7 @@ private boolean extractZip(final Path zipFile, final Path downloadDirectory) {
ArtifactUtils.extractFile(zipFile, unzipFolder);
} catch (IOException e) {
Activator.getLogger().error(String.format("Failed to extract zip contents for: %s, some features may not work", zipFile.toString()), e);
setErrorReason(ExceptionMetadata.scrubException(LspError.EXTRACTION_ERROR.toString(), e));
setErrorReason(ExceptionMetadata.scrubException(LspError.SERVER_ZIP_EXTRACTION_ERROR.toString(), e));
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private Optional<Manifest> getResourceFromCache() {
}
} catch (Exception e) {
Activator.getLogger().error("Error fetching resource from cache", e);
emitGetManifest(null, ManifestLocation.CACHE, ExceptionMetadata.scrubException(LspError.MANIFEST_FETCH_ERROR.toString(), e));
emitGetManifest(null, ManifestLocation.CACHE, ExceptionMetadata.scrubException(LspError.UNEXPECTED_MANIFEST_CACHE_ERROR.toString(), e));
}
return Optional.empty();
}
Expand Down Expand Up @@ -176,7 +176,7 @@ private Optional<Manifest> validateAndCacheLatest(final HttpResponse<String> res
return manifest;
} catch (Exception e) {
Activator.getLogger().error("Failed to cache manifest file", e);
emitGetManifest(null, ManifestLocation.REMOTE, ExceptionMetadata.scrubException(LspError.UNEXPECTED_CACHE_ERROR.toString(), e));
emitGetManifest(null, ManifestLocation.REMOTE, ExceptionMetadata.scrubException(LspError.MANIFEST_REMOTE_FETCH_ERROR.toString(), e));
}
return Optional.empty();
}
Expand Down

0 comments on commit 48738b4

Please sign in to comment.