azure-sdk-for-js: firewallRules listByServer throws Invalid Array Length error.

  • Package Name: @azure/arm-sql
  • Package Version: 6.0.0 and 7.0.0
  • Operating system: macOS Catalina 10.15.3
  • nodejs
    • version: 11.8.0
  • browser
    • name/version:
  • typescript
    • version: 3.7.4
  • Is the bug related to documentation in

Describe the bug Calling the firewallRules.listByServer() method of the @azure/arm-sql client causes an Invalid array length error to be thrown.

I’ve traced the issue back to the flattenResponse() method in msRest.node.js in the node_modules package directory. The _response object being passed into that function appears to have a property parsedBody, but that property is an object, and is passed into the tslib.__spreadArrays() function as if it were an array.

To Reproduce Steps to reproduce the behavior:

  1. Instantiate the sql management client with
import { SqlManagementClient } from "@azure/arm-sql";

const sqlManagementClient = new SqlManagementClient(credentials, subscriptionId)
  1. Call the firewallRules.listByServer function
const result = await sqlManagementClient.firewallRules.listByServer(resourcegroupName, serverName);

Expected behavior The function should return a list of firewall rules objects according to https://azuresdkdocs.blob.core.windows.net/$web/javascript/azure-arm-sql/6.0.0/classes/firewallrules.html#listbyserver

Screenshots image

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (15 by maintainers)

Most upvoted comments

After debugging for a while, it looks like the service is sending an XML body by default, and since the SWAGGER defines the response format as JSON our deserialization doesn’t know how to parse correctly.

@ebower12 as a workaround can you please try the following and let me know if it works?

const firewallRules = await client.firewallRules.listByServer(
    "ResourceGroup,
    "<ServerName",
    { customHeaders: { accept: "application/json" } }
  );

The problem occurred when flattening json respons via msrest. Ask codegen team to take a look at it