-
Notifications
You must be signed in to change notification settings - Fork 476
For #6564 - Only display URL hostname for tabstray #6566
For #6564 - Only display URL hostname for tabstray #6566
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6566 +/- ##
=========================================
Coverage 77.62% 77.62%
Complexity 4718 4718
=========================================
Files 627 627
Lines 22959 22959
Branches 3384 3384
=========================================
Hits 17823 17823
Misses 3746 3746
Partials 1390 1390
Continue to review full report at Codecov.
|
09cd495 to
30ab353
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, almost there! We should add tests to add coverage around that try-catch block.
We have a very short guide to generating a coverage report for the component you're working on to see where test coverage is lacking.
You should also have a look at setting up detekt and ktlint, which is used for most of our Android projects, so that it's run before pushing a patch up to CI. This will save personal time and CPU time to do it as a pre-push hook.
|
|
||
| var url = tab.url | ||
| try { | ||
| url = URL(tab.url).host | ||
| } | ||
| catch (e: MalformedURLException) { /* ignore error */ } | ||
| urlView?.text = url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the catch clause properly to set the fallback URL if the parsing fails.
| var url = tab.url | |
| try { | |
| url = URL(tab.url).host | |
| } | |
| catch (e: MalformedURLException) { /* ignore error */ } | |
| urlView?.text = url | |
| try { | |
| val tabHost = URL(tab.url).host | |
| urlView?.text = tabHost | |
| } catch (e: MalformedURLException) { | |
| urlView?.text = tab.url | |
| } |
It's generally not good practice to not handle the exceptions. If this is not the place you want to handle it, you can annotate the as a method that throws exceptions and the caller will then have to put the try-catch clause appropriately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we should lift the assignment out of the try catch e.g:
urlView?.text = try {
URL(tab.url).host
} catch (e: MalformedURLException) {
tab.url
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have an extension function for this we could re-use here:
Line 107 in f362c94
| fun String.tryGetHostFromUrl(): String = try { |
So, you can just call:
urlView?.text = tab.url.tryGetHostFromUrl()|
We also need to add a changelog entry. :) |
30ab353 to
134ec7b
Compare
134ec7b to
0bd7546
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks @darkwing !
bors r+
Build failed |
|
bors retry |
Build succeeded |
Fixes #6564. We don't want the entire URL, just the hostname, per @topotropic's direction.
Pull Request checklist
After merge