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

TypeError: Cannot read properties of undefined (reading 'warnIfFlagDeprecated') #528

Closed
endreymarcell-wise opened this issue Oct 18, 2022 · 16 comments

Comments

@endreymarcell-wise
Copy link

Describe the bug
I am running oclif as a dependency of twilio-cli (specifically, twilio-cli-core). When trying to run commands using the twilio command line tool, I get the following error:

/github/home/.twilio-cli/node_modules/@oclif/core/lib/command.js:153
        this.warnIfFlagDeprecated(results.flags ?? {});
             ^

TypeError: Cannot read properties of undefined (reading 'warnIfFlagDeprecated')
    at parse (/github/home/.twilio-cli/node_modules/@oclif/core/lib/command.js:153:14)
    at async /github/home/.twilio-cli/node_modules/@twilio-labs/plugin-flex/dist/utils/parser.js:113:42
    at async FlexPluginsDeploy.init (/github/home/.twilio-cli/node_modules/@twilio-labs/plugin-flex/dist/commands/flex/plugins/deploy.js:65:[24](https://github.com/transferwise/plugin-twilio-flex/actions/runs/3272804474/jobs/5384283979#step:10:25))
    at async FlexPluginsDeploy._run (/github/home/.twilio-cli/node_modules/@oclif/core/lib/command.js:79:13)
    at async Config.runCommand (/usr/local/lib/node_modules/twilio-cli/node_modules/@oclif/config/lib/config.js:173:24)
    at async Main.run (/usr/local/lib/node_modules/twilio-cli/node_modules/@oclif/command/lib/main.js:[27](https://github.com/transferwise/plugin-twilio-flex/actions/runs/3272804474/jobs/5384283979#step:10:28):9)
    at async Main._run (/usr/local/lib/node_modules/twilio-cli/node_modules/@oclif/command/lib/command.js:43:20)

The exact context of the exception is this:

    warnIfFlagDeprecated(flags) {
        for (const flag of Object.keys(flags)) {
            const deprecated = this.ctor.flags[flag]?.deprecated;
            if (deprecated) {
                this.warn((0, util_2.formatFlagDeprecationWarning)(flag, deprecated));
            }
        }
    }
    warnIfCommandDeprecated() {
        if (this.ctor.state === 'deprecated') {
            const cmdName = (0, index_1.toConfiguredId)(this.ctor.id, this.config);
            this.warn((0, util_2.formatCommandDeprecationWarning)(cmdName, this.ctor.deprecationOptions));
        }
    }
    async parse(options, argv = this.argv) {
        if (!options)
            options = this.constructor;
        const opts = { context: this, ...options };
        // the spread operator doesn't work with getters so we have to manually add it here
        opts.flags = options?.flags;
        opts.args = options?.args;
        const results = await Parser.parse(argv, opts);
        this.warnIfFlagDeprecated(results.flags ?? {});  // <-- ERROR
        return results;
    }

This looks like it could have been introduced by #527 (1.19.0)
Our job was still passing 21 hours ago; the PR linked was merged 16 hours ago; our first job today was 3 hours ago and it already failed.

My computer still @oclif/core v1.16.7 locally, and it seems to work without problems.

To Reproduce
Steps to reproduce the behavior:

  1. npm install -g twilio-cli
  2. twilio plugins:install @twilio-labs/plugin-flex
  3. twilio profiles:create

I understand it would be more useful to provide a direct reproduction which only relies on oclif, but if there's indeed an error in the code, it can hopefully be identified by the stack trace.

Expected behavior
Commands run successfully.

Environment (please complete the following information):

  • Ubuntu docker container with Node 16 installed, running on Github actions
@alpha-arpitjain
Copy link

Facing the same issue with Node 14 on aws codebuild containers. I tried it with twilio-cli version 5.0 as well and still it gives the same issue.

@bmcgrogan
Copy link

Yeah also facing the same issue. Build pipeline was successful in building using twilio-cli 3.4.1 yesterday. Tried the same build again today and got this error. Tried upgrading both flex-plugin and twilio-cli versions, but no success. Seems something has broken upstream, perhaps.

@moretalk
Copy link

Same issue here with twilio-cli 5.1.0

@mdonnalley
Copy link
Contributor

@endreymarcell-wise I'm unable to reproduce this with a freshly generated oclif cli and the latest oclif/core

So I'm assuming that there's something unique about your code base that's causing this. Can you provide any additional details that might help me reproduce it? Thanks!

@endreymarcell-wise
Copy link
Author

@bmcgrogan here's the dependency on oclif:
https://github.com/twilio/twilio-cli-core/blob/e8f132bd2b02717f28545337db91b582ca18575d/package.json#L45

As you can see, @twilio/cli-core depends on @oclif/core and since it's using ^ as the specifier, it'll get new minor versions as they roll out. So rolling back twilio-cli itself can not help.

FWIW my current workaround is to just remove the offending line from this one file on github:

echo 'Removing a breaking line from this dependency until https://github.com/oclif/core/issues/528 is fixed'
mv ~/.twilio-cli/node_modules/\@oclif/core/lib/command.js /tmp/command.js.bak
grep -v 'this.warnIfFlagDeprecated' /tmp/command.js.bak > ~/.twilio-cli/node_modules/\@oclif/core/lib/command.js

@endreymarcell-wise
Copy link
Author

Hey @mdonnalley, thanks for picking this up! I'm not sure what would be special about my codebase, and as you can see, others are also reporting the same issue.
Nevertheless, I'm happy to provide more details as much as I can (codebase is my company's, not mine).

@shrutiburman
Copy link

@mdonnalley, this might help: the issue somehow is prominent in Windows machines and Mac Silicon chips. I somehow couldn't reporduce it in my darwin os.

@moretalk
Copy link

I am reproducing it on Ubuntu via Github Actions.

@mdonnalley
Copy link
Contributor

mdonnalley commented Oct 18, 2022

@endreymarcell-wise thanks - any additional details would be greatly appreciated

I just tried the following:

  • git clone https://github.com/twilio/twilio-cli
  • npm install
  • bin/dev config list

And didn't see the issue. Is there a particular command of yours that this is happening on?

I also verified that the 1.19.0 is being used throughout the dependency tree:

~/repos/twilio/twilio-cli (main) » jq .version  node_modules/@oclif/core/package.json
"1.19.0"

@endreymarcell-wise
Copy link
Author

The exact command I am running is twilio flex:plugins:deploy. The background for this is that we are a customer of Twilio, we are using their product called Flex, and have a custom plugin for that which we deploy using Twilio's CLI. Not sure how you should be able to reproduce this setup without going through a whole lot of hassle. For what it's worth, the steps are described here: https://www.twilio.com/docs/flex/quickstart/getting-started-plugin

@mdonnalley
Copy link
Contributor

Thanks for the context - I was able to reproduce it with the following:

npm install -g twilio-cli
twilio plugins:install @twilio-labs/plugin-flex
twilio flex:plugins:create twilio-test
cd twilio-test
twilio flex:plugins:start

I'll report back once I know more about what's causing this

@mdonnalley
Copy link
Contributor

@endreymarcell-wise The issue is that you're passing the parse method in here without binding this to it

Changing super.parse to super.parse.bind(this) should resolve the issue.

Not binding this worked for you up to this point because parse didn't access any class properties or methods until the change introduced in 1.19.0

@endreymarcell-wise
Copy link
Author

Thanks for pinpointing the issue!
If you think the linked code is misusing the method, I'm happy to open an issue towards twilio, seeing that it's their code, not mine :)

@shrutiburman
Copy link

I'll get in touch with the respective team internally at Twilio. Thanks @mdonnalley !

@mdonnalley
Copy link
Contributor

@endreymarcell-wise @shrutiburman happy to help. I'm going to close this issue for now but feel free to reopen it if you feel it's necessary

@shrutiburman
Copy link

shrutiburman commented Oct 19, 2022

Folks following this thread, plugin-flex has released a patch with the fix, v6.0.2, that should solve this problem.

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

6 participants