Skip to content

Response parsing fails for empty results #83

@davidcockbill

Description

@davidcockbill

I tried to use Runtime.compileScript.

This returns two optional parameters. If they are not present, then ChromeDevToolsSession.parseChromeResponse() throws a NoSuchElementException when calling:

JsonNode first = elements.next();

The fix seems simple:

    Iterator<JsonNode> elements = response.getResult().elements();
    try {
      // We do our best to predict which kind of result to consume the response as, but there's
      // a small chance that a multi-result response has optional, absent members, and we try and
      // fail to parse it as a single-result response, which is why we catch the inner JsonMappingException.
      JsonNode first = elements.next(); // MOVED INTO TRY BLOCK
      if (elements.hasNext()) {
        return objectMapper.readValue(response.getResult().toString(), valueType);
      } else {
        return objectMapper.readValue(objectMapper.treeAsTokens(first), valueType);
      }
    } catch (JsonMappingException | NoSuchElementException e) { // CATCH NoSuchElementException
      try {
        return objectMapper.readValue(response.getResult().toString(), valueType);
      } catch (IOException e1) {
        throw new ChromeDevToolsException(e1);
      }
    } catch (IOException e2) {
      throw new ChromeDevToolsException(e2);
    }
  1. Move JsonNode first = elements.next() into try block
  2. Catch NoSuchElementException

@pschoenfelder it looks like you have recently updated this repo. My recent pull request has not been actioned. Can you let me know if HubSpot is happy for external submissions and if so who I ask. Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions