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

azure-pipelines-task-lib/task's execAsync fails on this.tool(...) #974

Closed
dnitsch opened this issue Sep 28, 2023 · 2 comments
Closed

azure-pipelines-task-lib/task's execAsync fails on this.tool(...) #974

dnitsch opened this issue Sep 28, 2023 · 2 comments

Comments

@dnitsch
Copy link

dnitsch commented Sep 28, 2023

Please check our current Issues to see if someone already reported this https://github.com/Microsoft/azure-pipelines-task-lib/issues

Environment

azure-pipelines-task-lib version: 4.6.0

Using esbuild to bundle and compile into cjs

Issue Description

When using the convenience wrapper around the tool runner from the azure-pipelines-task-lib/task the execAsync method fails Cannot read properties of undefined (reading 'tool'), the error is coming from here

let tr: trm.ToolRunner = this.tool(tool);

I am not sure how this was meant to have worked as this has nothing in the lexical scope of that standalone exported function, maybe I am being a bit thick here and am missing something "¯_(ツ)_/¯" .

Expected behaviour

When I run the below, I would expect it to work.

 await execAsync("az", ["account", "show"], {failOnStdErr: true, ignoreReturnCode: false })

Actual behaviour

Return TypeError: Cannot read properties of undefined (reading 'tool')

Steps to reproduce

    test("sample error with wrapper", async () => {
        // import { execAsync } from "azure-pipelines-task-lib/task"
        let err = null
        await execAsync("az", ["account", "show"], {failOnStdErr: true, ignoreReturnCode: false }).catch((ex: any) => {
            err = ex
        })
        expect(err).toBe(null)
    })
    test("no error via toolrunner chaining from task", async () => {
        // import { tool } from "azure-pipelines-task-lib/task"
        let err = null
        await tool("az").arg(["account", "show"]).execAsync().catch((ex: any) => {
            err = ex
        })
        expect(err).toBe(null)
    })

Happy to submit a PR to fix that behaviour - IF I got the right end of the stick here

Logs

@aleksandrlevochkin
Copy link
Contributor

Hi @dnitsch thank you for reporting this issue. I see the same code is used in exec and execSync methods. Do you have this error when calling those methods as well?

Copy link

This issue has had no activity in 90 days. Please comment if it is not actually stale

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

No branches or pull requests

2 participants