cli-microsoft365: UnhandledPromiseRejectionWarning: ParserError: Unexpected token type: Colon, value: :

#1402 # Description When searching the following error is returned:

UnhandledPromiseRejectionWarning: ParserError: Unexpected token type: Colon, value: :

Steps to reproduce

o365 spo search --query "IsDocument:1" --selectProperties "Path,Author,FileType"

Expected result

Search results are returned

Actual result

(node:572) UnhandledPromiseRejectionWarning: ParserError: Unexpected token type: Colon, value: :
    at Parser.parse (/home/sebastian/.npm-global/lib/node_modules/@pnp/office365-cli/node_modules/jmespath/jmespath.js:501:27)
    at Object.search (/home/sebastian/.npm-global/lib/node_modules/@pnp/office365-cli/node_modules/jmespath/jmespath.js:1659:25)
    at Function.logOutput (/home/sebastian/.npm-global/lib/node_modules/@pnp/office365-cli/dist/Utils.js:114:37)
    at UI.vorpal.pipe [as _pipeFn] (/home/sebastian/.npm-global/lib/node_modules/@pnp/office365-cli/dist/index.js:126:32)
    at UI.log (/home/sebastian/.npm-global/lib/node_modules/@pnp/office365-cli/node_modules/vorpal/dist/ui.js:436:48)
    at Session.session._log (/home/sebastian/.npm-global/lib/node_modules/@pnp/office365-cli/node_modules/vorpal/dist/session.js:93:24)
    at Session.session.log (/home/sebastian/.npm-global/lib/node_modules/@pnp/office365-cli/node_modules/vorpal/dist/session.js:78:20)
    at CommandInstance.log (/home/sebastian/.npm-global/lib/node_modules/@pnp/office365-cli/node_modules/vorpal/dist/command-instance.js:94:26)
    at SpoSearchCommand.printResults (/home/sebastian/.npm-global/lib/node_modules/@pnp/office365-cli/dist/o365/spo/commands/spo-search.js:271:17)
    at then.then (/home/sebastian/.npm-global/lib/node_modules/@pnp/office365-cli/dist/o365/spo/commands/spo-search.js:62:18)
(node:572) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:572) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Environment

  • Cloud Shell
    • o365 version: 2.11.0

About this issue

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

Commits related to this issue

Most upvoted comments

Sounds good to me

I think the suggested by Garry is what I as SharePoint developer 😄 would expect to see as options. --queryText makes sense in absence of the reserved for JMESPath --query. --enableFql is a flag that clearly identifies what we are after. I assume this flag will be used by users already familiar with the search apis and they would look for such flag since it is similar to the APIs. To Sebastian’s point of new query language, I do not think we should bother with this at the moment simply because this is not even on the roadmap and might never be introduced.

OK, so the issue is that with the introduction of support for JMESPath queries, we used the query option, which was previously used for specifying the search query in the spo search command. So instead the command processing your input as a search argument, it treats it as a JMESPath query. To fix this, we’ll need to rename the either option to avoid them colliding. Sorry for the trouble.

@sebastianrogers as a workaround for now, please use the short -q instead of --query.

To minimize the impact of this change (one command vs. all commands), I’d suggest renaming --query in spo search to --searchQuery. The short -q could stay as-is.

To add my thoughts to this, I have been accustomed to the notion of enabling FQL when searching against SharePoint using the REST API, this is in part due to the way that the SharePoint Search REST API has been implemented over the years.

The Search REST API uses KQL by default, most likely due to FAST historically being an add-on to SharePoint Search rather than part of the core Search service, so was added later to the API, this resulted in having to explicitly state that FQL should be used by passing the enableFql property in the query-string to make it explicit that FQL should be used rather than KQL.

GET http://_server_/_api/search/query?querytext='sharepoint'&enablefql=true

Source: https://docs.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview#enablefql

It’s also worth noting that out of the box web parts have also gone with the KQL approach first historically and this is also true with the way that the PnP Modern Search web parts have been implemented, so again something that people will be accustomed to.

My opinion is that we should follow the REST API, which I think is the most common and widely understood implementation, this provides a solution that would change --query to --queryText solving the conflict with JMESPath, and provide an --enableFql switch for explicitly defining that the query should use FQL.

o365 spo search --queryText "IsDocument:1" --selectProperties "Path,Author,FileType" --enableFql

Not a problem, suggest you call it --kql to make it clear what sort of query to use