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

Fix tool pull bad-sad for unauthorized response #40775

Merged

Conversation

gayaldassanayake
Copy link
Contributor

Purpose

When the settings.toml contains an incorrect access token, a BadSadError is produced during bal tools.

$ bal tool pull gayals

ballerina: Oh no, something really went wrong. Bad. Sad.

We appreciate it if you can report the code that broke Ballerina in
https://github.com/ballerina-platform/ballerina-lang/issues with the
log you get below and your sample code.

We thank you for helping make us better.

[2023-06-20 10:43:10,494] SEVERE {b7a.log.crash} - closed
java.lang.IllegalStateException: closed
	at okio.RealBufferedSource.select(RealBufferedSource.kt:83)
	at okhttp3.internal.Util.bomAwareCharset(Util.java:467)
	at okhttp3.ResponseBody.string(ResponseBody.java:181)
	at org.ballerinalang.central.client.CentralAPIClient.handleUnauthorizedResponse(CentralAPIClient.java:1521)
	at org.ballerinalang.central.client.CentralAPIClient.pullTool(CentralAPIClient.java:701)
	at io.ballerina.cli.cmd.ToolCommand.pullToolFromCentral(ToolCommand.java:346)
	at io.ballerina.cli.cmd.ToolCommand.handlePullCommand(ToolCommand.java:239)
	at io.ballerina.cli.cmd.ToolCommand.execute(ToolCommand.java:165)
	at java.base/java.util.Optional.ifPresent(Optional.java:183)
	at io.ballerina.cli.launcher.Main.main(Main.java:56)

This happens because the response body is already read for verbose printing and when it is re-read for printing the error, the body is empty.
This PR uses the initially read error for the error printing to avoid this.

Related to #40264

Approach

Describe how you are implementing the solutions along with the design details.

Samples

Provide high-level details about the samples related to this feature.

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

@gayaldassanayake gayaldassanayake requested a review from hevayo as a code owner June 20, 2023 05:27
@codecov
Copy link

codecov bot commented Jun 22, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.49 ⚠️

Comparison is base (bbc591e) 76.93% compared to head (e6f1541) 76.44%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #40775      +/-   ##
============================================
- Coverage     76.93%   76.44%   -0.49%     
- Complexity    53747    55276    +1529     
============================================
  Files          3332     3386      +54     
  Lines        200289   208252    +7963     
  Branches      25654    26955    +1301     
============================================
+ Hits         154086   159195    +5109     
- Misses        37819    40282    +2463     
- Partials       8384     8775     +391     
Impacted Files Coverage Δ
...ballerinalang/central/client/CentralAPIClient.java 37.04% <0.00%> (-11.72%) ⬇️

... and 570 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@azinneera azinneera merged commit 97d1e07 into ballerina-platform:master Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants