berry icon indicating copy to clipboard operation
berry copied to clipboard

[Feature] Better HTTP request error logs

Open yarinsa opened this issue 3 years ago • 8 comments

  • [x] I'd be willing to implement this feature (contributing guide)
  • [x] This feature is important to have in this repository; a contrib plugin wouldn't do

Describe the user story

A clear and concise description of what workflow is meant to be improved. Example: "As a developer, I often want to know what is the reason for the HTTP error, but I often face no logs but error code".

Describe the solution you'd like

Add 'verbose' flag to the command so it prints a better logging

Describe the drawbacks of your solution

I think it will be easier to cover specific & common cases like in 'yarn install / yarn npm publish' since most of the errors are faced when dealing with private registries

Describe alternatives you've considered

why not make it a plugin? I think it crucial to enable better debugging within yarn tool itself

yarinsa avatar Aug 23 '22 06:08 yarinsa

We already print most of the info we have (in particular the status code and the URL that failed); what else would you expect to see?

arcanis avatar Aug 23 '22 07:08 arcanis

The response body. I am getting 403 from jFrog in their body they say it's an existing package, but all I am seeing is Forbidden.

When adding console.log myself to the yarn.cjs

response body {
  errors: [
    {
      status: 403,
      message: "Not enough permissions to delete/overwrite artifact 'npm-dev-local:@scope/package' (user: '[email protected]' needs DELETE permission)."
    }
  ]
}

VS yarn logs

➤ YN0035: The remote server failed to provide the requested resource
➤ YN0035:   Response Code: 403 (Forbidden)
➤ YN0035:   Request Method: PUT
➤ YN0035:   Request URL: https://company.jfrog.io/artifactory/artifactory-name/package-name
➤ YN0000: Failed with errors in 0s 106ms

This log could be very useful and save a lot of time :) I think the fix should be here

yarinsa avatar Aug 29 '22 12:08 yarinsa

@arcanis I have created a fix branch on my machine (pulled yarn and setup a development env). How can I push this code to a new branch and offer PR? (getting permission issues).

Before the PR: Screen Shot 2022-08-29 at 19 27 41

After my PR: Screen Shot 2022-08-29 at 19 51 46

Motivation: I am working in a startup where we use jFrog as our artifactory.

  1. jFrog returns 403 for trying to push existing package (I would assume it would return 409), since there is insufficient permissions to remove the old package.
  2. jFrog returns 409 for trying to push a folder. (another issue, I am gonna try to debug)

I couldn't find these reasons / debug from yarn side or from jFrog side. I ended up having a yarn.cjs and inserting my own console logs there to see the response.body.

Conclusion it would be better to print the response body. Since we cant rely on it's structure (for example { errors: [...] }) I think it would be the best to show a raw body.

This could save me a lot of days and I believe can be helpful to more people.

yarinsa avatar Aug 29 '22 17:08 yarinsa

While I understand the issue, it doesn't look super good and it takes a lot of vertical space. Rather than displaying the body, I'd prefer to store it in a temporary file and print its path (which is the same thing we do for build scripts).

arcanis avatar Aug 29 '22 17:08 arcanis

@arcanis Sounds to me like a great idea, I will try to find a reference and implement. Can I get your help pushing a branch? Thanks

yarinsa avatar Aug 29 '22 21:08 yarinsa

Can I get your help pushing a branch?

See https://docs.github.com/en/get-started/quickstart/contributing-to-projects

merceyz avatar Oct 01 '22 17:10 merceyz

Thank you, a bit out of context :) I will go back to it and try in a few days

yarinsa avatar Oct 12 '22 10:10 yarinsa

+1

It would be really useful to know that Invalid authentication (as an anonymous user) actually means (in this case) 401 "Access Denied: The Personal Access Token used has expired. - Azure DevOps Server" without having to do 30 minutes of step-through debugging of minified js.

AvremelM avatar Jan 18 '24 16:01 AvremelM