eclipse-velocitas / cli

Velocitas CLI
Apache License 2.0
4 stars 2 forks source link

[Bug]: No error message if Github rate limit exceeded #326

Open erikbosch opened 1 month ago

erikbosch commented 1 month ago

Severity

Medium

What release version, tag or commit-hash did you use?

main

Current Behavior

In some cases a clone request may be denied due to Github rate limiting. This may typically happen for corporate networks where the same IP is used by a large number of users. When doing velocitas init you may get messages like:

Error: Can't find matching version for v2.5.2. Prefix with '@' for a branch or use a valid semantic version.

Even if the version actually existed and the problem is that clone failed!

Steps to Reproduce

Not easy - as you likely need quite huge number of github API requests

Expected Behavior

We cannot do anything about the rate limiting, but we should better print something like

"Clone failed for xxx"
<github message>

Possible Solution

Follow up on the clone, either identify an error by the returned simple-git message, or do some sanity check of the result and if expected files are not there give error/warning

private async _cloneRepository(packageDir: string, cloneOpts: string[]): Promise<void> {
        await this.git.clone(this.packageConfig.getPackageRepo(), packageDir, cloneOpts);
    }

Additional Information

I do not like this template!

Code of Conduct

erikbosch commented 1 month ago

For reference - some other error messages. One can argue that th error style reported to the user differs a bit, but you get sufficient info to troubleshoot. Potentially one could use try/catch and only print the stack trace in debug mode.

Current printout if repo does not exist

vscode ➜ /workspaces/cp--example-1 (main) $ velocitas init
Initializing Velocitas packages ...
... 'devenv-runtimes:v4.0.6' already installed.
... 'devenv-github-workflows:v6.1.3' already installed.
... 'devenv-github-templates:v1.0.5' already installed.
GitError: Cloning into bare repository '/home/vscode/.velocitas/packages/devenv-devcontainer-zetup/_cache'...
remote: Repository not found.
fatal: repository 'https://github.com/SoftwareDefinedVehicle/devenv-devcontainer-zetup.git/' not found

    at Object.action (/snapshot/cli/node_modules/simple-git/dist/cjs/index.js:1451:25)
    at PluginStore.exec (/snapshot/cli/node_modules/simple-git/dist/cjs/index.js:1500:29)
    at /snapshot/cli/node_modules/simple-git/dist/cjs/index.js:1927:43
    at new Promise (<anonymous>)
    at GitExecutorChain.handleTaskData (/snapshot/cli/node_modules/simple-git/dist/cjs/index.js:1925:16)
    at GitExecutorChain.<anonymous> (/snapshot/cli/node_modules/simple-git/dist/cjs/index.js:1909:44)
    at Generator.next (<anonymous>)
    at fulfilled (/snapshot/cli/node_modules/simple-git/dist/cjs/index.js:52:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  task: {
    commands: [
      'clone',
      '--bare',
      'https://github.com/SoftwareDefinedVehicle/devenv-devcontainer-zetup.git',
      '/home/vscode/.velocitas/packages/devenv-devcontainer-zetup/_cache'
    ],
    format: 'utf-8',
    parser: [Function: parser]
  }
}
... Downloading package: 'devenv-devcontainer-zetup:@erik_offline'
GitError: Cloning into '/home/vscode/.velocitas/packages/devenv-devcontainer-zetup/@erik_offline'...
remote: Repository not found.

Branch does not exist

Initializing Velocitas packages ...
... 'devenv-runtimes:v4.0.6' already installed.
... 'devenv-github-workflows:v6.1.3' already installed.
... 'devenv-github-templates:v1.0.5' already installed.
... Downloading package: 'devenv-devcontainer-setup:@erik_offline'
GitError: error: pathspec 'erik_offline' did not match any file(s) known to git

    at Object.action (/snapshot/cli/node_modules/simple-git/dist/cjs/index.js:1451:25)
    at PluginStore.exec (/snapshot/cli/node_modules/simple-git/dist/cjs/index.js:1500:29)
    at /snapshot/cli/node_modules/simple-git/dist/cjs/index.js:1927:43
    at new Promise (<anonymous>)
    at GitExecutorChain.handleTaskData (/snapshot/cli/node_modules/simple-git/dist/cjs/index.js:1925:16)
    at GitExecutorChain.<anonymous> (/snapshot/cli/node_modules/simple-git/dist/cjs/index.js:1909:44)
    at Generator.next (<anonymous>)
    at fulfilled (/snapshot/cli/node_modules/simple-git/dist/cjs/index.js:52:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  task: {
    commands: [ 'checkout', 'erik_offline' ],
    format: 'utf-8',
    parser: [Function: parser]
  }
}
    Error: Cannot find package devenv-devcontainer-setup:@erik_offline

Tag does not exist


vscode ➜ /workspaces/cp--example-1 (main) $ velocitas init
Initializing Velocitas packages ...
... 'devenv-runtimes:v4.0.6' already installed.
... 'devenv-github-workflows:v6.1.3' already installed.
... 'devenv-github-templates:v1.0.5' already installed.
    Error: Can't find matching version for v2.5.5. Prefix with '@' for a branch or use a valid semantic version.
mikehaller commented 1 month ago

Using velocitas init -v currently does not yield much more information to the user:

vscode ➜ /workspaces/example-vehicle-service (main) $ velocitas init -v
Initializing Velocitas packages ...
... Could not check the server version for devenv-runtimes
... Resolved 'devenv-runtimes:v4.0.6' to version: 'v4.0.6'
... 'devenv-runtimes:v4.0.6' already installed.
... Could not check the server version for devenv-github-workflows
... Resolved 'devenv-github-workflows:v6.0.4' to version: 'v6.0.4'
... 'devenv-github-workflows:v6.0.4' already installed.
... Could not check the server version for devenv-github-templates
... Resolved 'devenv-github-templates:v1.0.5' to version: 'v1.0.5'
... 'devenv-github-templates:v1.0.5' already installed.
... Could not check the server version for devenv-devcontainer-setup
    Error: Can't find matching version for v2.5.2. Prefix with '@' for a branch or use a valid semantic version.
vscode ➜ /workspaces/example-vehicle-service (main) $

At least for verbose logging enabled with -v it would be nice to get the corresponding error line from the output of the executed git command, e.g.:

remote: Repository not found.
fatal: repository 'https://github.com/SoftwareDefinedVehicle/devenv-devcontainer-zetup.git/' not found

Stack trace information would indeed be more valuable for contributors, e.g. as you say something like debug logging with --debug.

erikbosch commented 1 month ago

I agree that it could be a good long term improvement to improve when/how we give printouts and support different levels, like normal, verbose and debug. Like using "verbose" for what a customer developer may need to troubleshoot, and debug for what an velocitas developer may need