tolgee / tolgee-cli

The Tolgee CLI
MIT License
16 stars 11 forks source link

Unhandled exception when running tolgee push #47

Closed Davasny closed 1 year ago

Davasny commented 1 year ago

Exception

>node  "C:\Users\jakub\AppData\Local\Yarn\Data\global\node_modules\.bin\\..\@tolgee\cli\dist\index.js" push ./src/**/*.ts?(x) 
🔴 An unexpected error occurred while running the command.
🔴 Please report this to our issue tracker: https://github.com/tolgee/tolgee-cli/issues
TypeError: Cannot read properties of undefined (reading 'startsWith')
    at loadProjectId (C:\Users\jakub\AppData\Local\Yarn\Data\global\node_modules\@tolgee\cli\dist\index.js:52:21)
    at Object.preHandler [as callback] (C:\Users\jakub\AppData\Local\Yarn\Data\global\node_modules\@tolgee\cli\dist\index.js:79:9)
    at async Command.parseAsync (C:\Users\jakub\AppData\Local\Yarn\Data\global\node_modules\commander\lib\command.js:935:5)
    at async run (C:\Users\jakub\AppData\Local\Yarn\Data\global\node_modules\@tolgee\cli\dist\index.js:144:9)

Affected line is in function loadProjectId

function loadProjectId(cmd) {
    const opts = cmd.optsWithGlobals();
    if (opts.apiKey.startsWith(constants_1.API_KEY_PAK_PREFIX)) {
        // Parse the key and ensure we can access the specified Project ID
        const projectId = client_1.default.projectIdFromKey(opts.apiKey);
        program.setOptionValue('projectId', projectId);
        if (opts.projectId !== -1 && opts.projectId !== projectId) {
            (0, logger_1.error)('The specified API key cannot be used to perform operations on the specified project.');
            (0, logger_1.info)(`The API key you specified is tied to project #${projectId}, you tried to perform operations on project #${opts.projectId}.`);
            (0, logger_1.info)('Learn more about how API keys in Tolgee work here: https://tolgee.io/platform/account_settings/api_keys_and_pat_tokens');
            process.exit(1);
        }
    }
}

Environment:

Windows: 10 PRO
yarn: 1.22.5
node: v18.16.0

tolgee installed via yarn global
tolgee: 1.1.0

Steps

  1. yarn global add @tolgee/cli
  2. tolgee login <token with full admin>
  3. tolgee push './src/**/*.ts?(x)'
github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 1.1.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: