8000 Error: Unhandled error: SyntaxError: Unexpected token '{' · Issue #401 · actions/github-script · GitHub
[go: up one dir, main page]

Skip to content

Error: Unhandled error: SyntaxError: Unexpected token '{' #401

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

Closed
denys-parloa opened this issue Jun 30, 2023 · 2 comments
Closed

Error: Unhandled error: SyntaxError: Unexpected token '{' #401

8000
denys-parloa opened this issue Jun 30, 2023 · 2 comments

Comments

@denys-parloa
Copy link

Hello!

I use this workflow element (To Reproduce section) to display the terraform plan, the variable ${{ steps.show-plan.outputs.stdout }} contains a string with special characters plus json elements.

How to avoid this issue? Probably I need to encode the string somehow ..

Tried including result-encoding: string but same result.
By the way, about a month ago this workflow worked fine.

Describe the bug

SyntaxError: Unexpected token '{'
    at new AsyncFunction (<anonymous>)
    at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15143:16)
    at main (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15236:26)
    at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:15217:1
    at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:15268:3
    at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15[271](https://github.com/parloa/parloa-infra/actions/runs/5422135137/jobs/9858405881#step:12:272):12)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
Error: Unhandled error: SyntaxError: Unexpected token '{'
A clear and concise description of what the bug is.

To Reproduce

   - name: Update Pull Request
      uses: actions/github-script@v6
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        result-encoding: string
        script: |
          const output = `
          <details><summary>Show Plan</summary>
          \`\`\`\n
          ${{ steps.show-workspace.outputs.stdout }}
          ${{ steps.show-var-file.outputs.stdout }}
          ${{ steps.show-plan.outputs.stdout }}
          \`\`\`
          </details>
          `;
          
          github.rest.issues.createComment({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            body: output
          })

Desktop (please complete the following information):

  • GitHub Action
@joshmgross
Copy link
Member

The values you're injecting into that template string are likely invalid Javascript and aren't being escaped correctly.

I'd recommend setting those context values as environment variables and referencing them via process.env and the regular ${} template literal string interpolation.

   - name: Update Pull Request
      uses: actions/github-script@v6
      env:
        SHOW_WORKSPACE_OUTPUT: ${{ steps.show-workspace.outputs.stdout }}
        SHOW_VAR_FILE_OUTPUT: ${{ steps.show-var-file.outputs.stdout }}
        SHOW_PLAN_OUTPUT: ${{ steps.show-plan.outputs.stdout }}
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        result-encoding: string
        script: |
          const output = `
          <details><summary>Show Plan</summary>
          \`\`\`\n
          ${process.env.SHOW_WORKSPACE_OUTPUT}
          ${process.env.SHOW_VAR_FILE_OUTPUT}
          ${process.env.SHOW_PLAN_OUTPUT}
          \`\`\`
          </details>
          `;
          
          github.rest.issues.createComment({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            body: output
          })

@denys-parloa
Copy link
Author

thank you!
it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0