Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cognitive Services Text Analytics - TypeError: Cannot use 'in' operator to search for 'showStats' in true #4168

Closed
1 of 6 tasks
kellyjandrews opened this issue Jul 3, 2019 · 4 comments
Labels
Client This issue points to a problem in the data-plane of the library. Cognitive - Text Analytics customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@kellyjandrews
Copy link

kellyjandrews commented Jul 3, 2019

  • Package Name: @azure/cognitiveservices-textanalytics
  • Package Version: 3.0.0
  • Operating system:
  • nodejs
    • version: 11.11.0
  • browser
    • name/version:
  • typescript
    • version:
  • Is the bug related to documentation in

Describe the bug
UnhandledPromiseRejectionWarning: TypeError: Cannot use 'in' operator to search for 'showStats' in true

To Reproduce
Steps to reproduce the behavior:

  1. Run the following code:
const msRestNodeAuth = require("@azure/ms-rest-nodeauth");
const {TextAnalyticsClient} = require("@azure/cognitiveservices-textanalytics");

const clientId = "clientId";
const secret = "secret";
const tenantId = "tenantId";
 msRestNodeAuth.loginWithServicePrincipalSecretWithAuthResponse(clientId, secret, tenantId).then((authRes) => {
    const client = new TextAnalyticsClient(authRes.credentials, "subscriptionID");
    const showStats = true;
      const languageBatchInput = {
        documents: [{
          countryHint: "testcountryHint",
          id: "testid",
          text: "testtext"
        }]
      };
        client.detectLanguage(showStats, languageBatchInput).then((result) => {
          console.log("The result is:");
          console.log(result);
        });
  }).catch((err) => {
    console.log(err);
  });

Expected behavior
Return a text analysis.

Screenshots
If applicable, add screenshots to help explain your problem.
Full stack trace:

UnhandledPromiseRejectionWarning: TypeError: Cannot use 'in' operator to search for 'showStats' in true
    at getPropertyFromParameterPath (/Users/kellyjandrews/Google Drive/Apps/sentiment-analysis/sms-sentiment-azure/node_modules/@azure/ms-rest-js/dist/msRest.node.js:3625:54)
    at getOperationArgumentValueFromParameterPath (/Users/kellyjandrews/Google Drive/Apps/sentiment-analysis/sms-sentiment-azure/node_modules/@azure/ms-rest-js/dist/msRest.node.js:3583:44)
    at getOperationArgumentValueFromParameter (/Users/kellyjandrews/Google Drive/Apps/sentiment-analysis/sms-sentiment-azure/node_modules/@azure/ms-rest-js/dist/msRest.node.js:3570:12)
    at TextAnalyticsClient.ServiceClient.sendOperationRequest (/Users/kellyjandrews/Google Drive/Apps/sentiment-analysis/sms-sentiment-azure/node_modules/@azure/ms-rest-js/dist/msRest.node.js:3382:47)
    at TextAnalyticsClient.detectLanguage (/Users/kellyjandrews/Google Drive/Apps/sentiment-analysis/sms-sentiment-azure/node_modules/@azure/cognitiveservices-textanalytics/dist/cognitiveservices-textanalytics.js:853:25)
    at msRestNodeAuth.loginWithServicePrincipalSecretWithAuthResponse.then (/Users/kellyjandrews/Google Drive/Apps/sentiment-analysis/sms-sentiment-azure/index.js:70:16)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
@maggiepint maggiepint added Client This issue points to a problem in the data-plane of the library. Cognitive Services customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention Workflow: This issue is responsible by Azure service team. and removed triage labels Jul 3, 2019
@maggiepint
Copy link
Contributor

Thanks for letting us know about this. We have routed to the appropriate team for follow-up.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Aug 10, 2019

@kellyjandrews The first argument to client.detectLanguage should be a json object but a boolean value is being passed here.
Please update your code from
client.detectLanguage(showStats, languageBatchInput)
to
client.detectLanguage({ showStats, languageBatchInput}) and that should solve the problem.

More details if you are interested.

The error is coming from https://github.com/Azure/ms-rest-js/blob/master/lib/serviceClient.ts#L519

const parameterPathPart: string = parameterPath[i];
    // Make sure to check inherited properties too, so don't use hasOwnProperty().
    if (parent != undefined && parameterPathPart in parent) {
      parent = parent[parameterPathPart];
    } else {
      break;
    }

This code tries to look for showStats property in the user provided value.
Since you have provided true instead of {showStats: true} you get the TypeError.

@kellyjandrews
Copy link
Author

kellyjandrews commented Aug 26, 2019

This documentation is inaccurate then - https://azure.github.io/azure-sdk-for-js/cognitiveservices-textanalytics/index.html

import * as msRest from "@azure/ms-rest-js";
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
import { TextAnalyticsClient, TextAnalyticsModels, TextAnalyticsMappers } from "@azure/cognitiveservices-textanalytics";
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];

msRestNodeAuth.interactiveLogin().then((creds) => {
  const client = new TextAnalyticsClient(creds, subscriptionId);
  const showStats = true; // <--- this is the boolean as documented
  const languageBatchInput: TextAnalyticsModels.LanguageBatchInput = {
    documents: [{
      countryHint: "testcountryHint",
      id: "testid",
      text: "testtext"
    }]
  };
  client.detectLanguage(showStats, languageBatchInput).then((result) => {   // <--- this line is incorrect
    console.log("The result is:");
    console.log(result);
  });
}).catch((err) => {
  console.error(err);
});

@ramya-rao-a
Copy link
Contributor

I agree, and I have an issue #4289 that is tracking the problems with the samples in the readme files for all the cognitive services libraries.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. Cognitive - Text Analytics customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

4 participants