Skip to content

Broken stored procedure body when using modern JavaScript syntax #137

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

Open
bak-t opened this issue Jul 4, 2018 · 3 comments
Open

Broken stored procedure body when using modern JavaScript syntax #137

bak-t opened this issue Jul 4, 2018 · 3 comments
Assignees
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.

Comments

@bak-t
Copy link
Contributor

bak-t commented Jul 4, 2018

Description

When using Set-CosmosDbStoredProcedure/New-CosmosDbStoredProcedure cmdlet to change/create stored procedure the body becomes broken.

For example code:

...
if (someCondition)
  throw new Error(`Root entity (id: ${entity.id}) already exists`);
...

becomes

...
if (someCondition)
  throw new Error(
oot entity (id: ${entity.id}) already exists`);
...

Environment Details

  • Powershell
    • Version: 5.1.15063.1155
    • Host: Console
  • OS: Windows 10 Professional (10.0.15063)
  • CosmosDB module version 2.1.2.514

Additional observations

In Set-CosmosDbStoredProcedure stored procedure body is encoded using:

$StoredProcedureBody = ((($StoredProcedureBody -replace '`n', '\n') -replace '`r', '\r') -replace '"', '\"')

The issue is in search string of -replace operation which should be enclosed in double quotes.
Also code to encode body can be replaced with

$StoredProcedureBody = ConvertTo-Json -InputObject $StoredProcedureBody

And even whole REST request body can be built like this:

$requestBody = ConvertTo-Json -Depth 100 -InputObject @{
  id = $id
  body = $StoredProcedureBody
}

P.S.

I hope to prepare pull request during next few days.

@PlagueHO PlagueHO added bug The issue is a bug. in progress The issue is being actively worked on by someone. labels Jul 4, 2018
@PlagueHO
Copy link
Owner

PlagueHO commented Jul 4, 2018

Awesome! Thanks for logging this @bak-t - look forward to the PR! 😁

@PlagueHO PlagueHO reopened this Sep 3, 2018
@PlagueHO
Copy link
Owner

PlagueHO commented Sep 3, 2018

Due to this difference between Windows PowerShell and PowerShell Core 6.0.x, this issue needs to be reopened. If this difference is addressed in PowerShell Core 6.1 then this issue can be closed again. Otherwise some additional steps will need to be taken to improve the conversion to work on PowerShell Core.

@PlagueHO
Copy link
Owner

Now that PowerShell Core 6.1 is long out we should be able to document and close this issue by defining a minimum recommended PS version and ensuring the tests work correctly with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. in progress The issue is being actively worked on by someone.
Projects
None yet
Development

No branches or pull requests

2 participants