You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "Steve Loughran (JIRA)" <ji...@apache.org> on 2017/06/06 12:16:18 UTC

[jira] [Commented] (HADOOP-14385) HttpExceptionUtils#validateResponse swallows exceptions

    [ https://issues.apache.org/jira/browse/HADOOP-14385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16038756#comment-16038756 ] 

Steve Loughran commented on HADOOP-14385:
-----------------------------------------

LGTM
+1 for applying to 2.8.x+

thanks for this, better diagnostics is something which benefits everyone, even though its never headline improvements in a release

> HttpExceptionUtils#validateResponse swallows exceptions
> -------------------------------------------------------
>
>                 Key: HADOOP-14385
>                 URL: https://issues.apache.org/jira/browse/HADOOP-14385
>             Project: Hadoop Common
>          Issue Type: Improvement
>            Reporter: Wei-Chiu Chuang
>            Assignee: Wei-Chiu Chuang
>            Priority: Trivial
>         Attachments: HADOOP-14385.001.patch, HADOOP-14385.002.patch
>
>
> In the following code
> {code:title=HttpExceptionUtils#validateResponse}
> try {
>         es = conn.getErrorStream();
>         ObjectMapper mapper = new ObjectMapper();
>         Map json = mapper.readValue(es, Map.class);
>         json = (Map) json.get(ERROR_JSON);
>         String exClass = (String) json.get(ERROR_CLASSNAME_JSON);
>         String exMsg = (String) json.get(ERROR_MESSAGE_JSON);
>         if (exClass != null) {
>           try {
>             ClassLoader cl = HttpExceptionUtils.class.getClassLoader();
>             Class klass = cl.loadClass(exClass);
>             Constructor constr = klass.getConstructor(String.class);
>             toThrow = (Exception) constr.newInstance(exMsg);
>           } catch (Exception ex) {
>             toThrow = new IOException(String.format(
>                 "HTTP status [%d], exception [%s], message [%s] ",
>                 conn.getResponseCode(), exClass, exMsg));
>           }
>         } else {
>           String msg = (exMsg != null) ? exMsg : conn.getResponseMessage();
>           toThrow = new IOException(String.format(
>               "HTTP status [%d], message [%s]", conn.getResponseCode(), msg));
>         }
>       } catch (Exception ex) {
>         toThrow = new IOException(String.format( <-- here
>             "HTTP status [%d], message [%s]", conn.getResponseCode(),
>             conn.getResponseMessage()));
>       }
> {code}
> If the an exception is thrown within the try block, the initial exception is swallowed, and it doesn't help debugging.
> We had to cross reference this exception with the KMS server side to guess what happened.
> IMHO the IOException thrown should also carry the initial exception. It should also print exClass and exMsg. It probably failed to instantiate an exception class.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org