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

feature: Give helpful advice when profile missing on host #461

Conversation

rtyley
Copy link
Contributor

@rtyley rtyley commented Dec 27, 2023

This updates the error message given when a profile is not found on a host (note Sonatype currently has 2 OSS hosts - oss.sonatype.org & s01.oss.sonatype.org - and any profile will only exist on one of the hosts).

image

(example here)

There can be two possible causes when a profile is not found on a host:

  1. The profile name is misspelt/incorrect (eg 'com.gnu' or 'john.smith' instead of 'com.gu')
  2. The profile is actually on the other Sonatype OSS host

The original error message really only indicated the possibility of the 1st problem, but the 2nd issue is increasingly likely - since February 2021 new profiles have only been registered on the new host s01.oss.sonatype.org, and sbt-sonatype defaults to using the older host, oss.sonatype.org.

The new error message aims to make the user aware of the 2 possible causes of the 'missing profile' problem, and offer advice on how the 2nd problem could be corrected.

Before:

Profile com.gu is not found. Check your sonatypeProfileName setting in build.sbt

After:

Profile com.gu is not found on oss.sonatype.org. In your sbt settings, check your sonatypeProfileName and sonatypeCredentialHost (try s01.oss.sonatype.org?)"

Sonatype host is determined by-profile (not by-user)

Note that in the past, there's been a bit of confusion (ok, I've been a bit confused!) about whether hosts are assigned on a by-user or by-profile basis (many users can be granted access by Sonatype to upload to one profile, eg we at the Guardian have that for our com.gu profile). It's definitely per-profile though - so sonatypeProfileName dictates which sonatypeCredentialHost you want to be using.

As a user (eg, for me, with my Sonatype user account 'roberto') working on a variety of projects with different profiles (eg, for me, working on projects under com.gu, com.madgag & org.scanamo) when I'm performing a release I'll be uploading to either oss.sonatype.org, or s01.oss.sonatype.org, depending on which profile/groupId that particular project lives under.

This updates the error message given when a profile is not found on a host (note Sonatype currently has 2
OSS hosts - `oss.sonatype.org` & `s01.oss.sonatype.org` and any profile will only exist on _one_ of the
hosts).

There can be two possible causes when a profile is not found on a host:

1. The profile name is misspelt/incorrect (eg 'com.gnu' or 'john.smith' instead of 'com.gu')
2. The profile is actually on the _other_ Sonatype OSS host

The original error message really only indicated the possibility of the _1st_ problem, but the 2nd issue
is increasingly likely - since February 2021 new profiles have _only_ been registered on the new host
`s01.oss.sonatype.org` (https://central.sonatype.org/news/20210223_new-users-on-s01/), and `sbt-sonatype`
defaults to using the other host, `oss.sonatype.org`.

The new error message aims to make the user aware of the 2 possible causes of the 'missing profile'
problem, and offer advice on how the 2nd problem could be corrected.

Before:

> Profile com.gu is not found. Check your sonatypeProfileName setting in build.sbt

After:

> Profile com.gu is not found on oss.sonatype.org. In your sbt settings, check your sonatypeProfileName and sonatypeCredentialHost (try s01.oss.sonatype.org?)"
@rtyley rtyley force-pushed the give-helpful-message-when-profile-not-found-on-host branch from 373ae8b to a0a1759 Compare December 27, 2023 11:28
Comment on lines -55 to +58
lazy val repoUri = {
def repoBase(url: String) = if (url.endsWith("/")) url.dropRight(1) else url
val url = repoBase(repositoryUrl)
url
}
private val pathPrefix = {
new java.net.URL(repoUri).getPath
}
lazy val repoUri: URI = URI.create(repositoryUrl.stripSuffix("/"))

private val pathPrefix = repoUri.getPath
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a simplification of repoUri - it gets much shorter!

Comment on lines 25 to 36
case class MISSING_PROFILE(profileName: String, host: String) extends ErrorCode {
val problem = s"Profile $profileName is not found on $host"

val possibleAlternativeHosts: Seq[String] = Sonatype.KnownOssHosts.filterNot(_ == host)

val hostAdvice = s"try ${possibleAlternativeHosts.mkString(", or ")}?"

val advice: String =
s"In your sbt settings, check your sonatypeProfileName and sonatypeCredentialHost ($hostAdvice)"

val message: String = s"$problem. $advice"
}
Copy link
Contributor Author

@rtyley rtyley Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing MISSING_PROFILE into a case class lets us break down the construction of the error message into separate fields, and makes it easier to construct good assertions on the error messages in SonatypeExceptionTest!

@rtyley rtyley marked this pull request as ready for review December 27, 2023 11:34
@xerial
Copy link
Owner

xerial commented Jan 10, 2024

i just noticed this PR. Will take a look

@xerial xerial self-assigned this Jan 10, 2024
@rtyley
Copy link
Contributor Author

rtyley commented Jan 17, 2024

i just noticed this PR. Will take a look

Thanks @xerial! How does it look to you? I'm happy to make changes if required?

@@ -59,6 +59,7 @@ object Sonatype extends AutoPlugin with LogSupport {

val sonatypeLegacy = "oss.sonatype.org"
val sonatype01 = "s01.oss.sonatype.org"
val KnownOssHosts = Seq(sonatypeLegacy, sonatype01)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val KnownOssHosts = Seq(sonatypeLegacy, sonatype01)
val knownOssHosts = Seq(sonatypeLegacy, sonatype01)

For consistency of variable naming.

@xerial xerial changed the title Give helpful advice when profile missing on host feture: Give helpful advice when profile missing on host Jan 18, 2024
@xerial xerial changed the title feture: Give helpful advice when profile missing on host feature: Give helpful advice when profile missing on host Jan 18, 2024
@xerial xerial merged commit 17e3464 into xerial:master Jan 18, 2024
5 checks passed
@xerial
Copy link
Owner

xerial commented Jan 18, 2024

Merged with some fixes for code cosmetics

@rtyley
Copy link
Contributor Author

rtyley commented Jan 18, 2024

Thank you!

mergify bot referenced this pull request in slick/slick Jun 27, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[org.xerial.sbt:sbt-sonatype](https://togithub.com/xerial/sbt-sonatype)
| plugin | minor | `3.10.0` -> `3.11.0` |

---

### Release Notes

<details>
<summary>xerial/sbt-sonatype (org.xerial.sbt:sbt-sonatype)</summary>

###
[`v3.11.0`](https://togithub.com/xerial/sbt-sonatype/releases/tag/v3.11.0)

[Compare
Source](https://togithub.com/xerial/sbt-sonatype/compare/v3.10.0...v3.11.0)

<!-- Release notes generated using configuration in .github/release.yml
at v3.11.0 -->

#### What's Changed

##### 🚀 Features

- feature: Support the new Sonatype Central API by
[@&#8203;Andrapyre](https://togithub.com/Andrapyre) in
[https://github.com/xerial/sbt-sonatype/pull/474](https://togithub.com/xerial/sbt-sonatype/pull/474)

##### 🔗 Dependency Updates

- Update scalafmt-core to 3.7.17 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/456](https://togithub.com/xerial/sbt-sonatype/pull/456)
- Bump actions/setup-java from 3 to 4 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/xerial/sbt-sonatype/pull/457](https://togithub.com/xerial/sbt-sonatype/pull/457)
- Update sbt, scripted-plugin to 1.9.8 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/458](https://togithub.com/xerial/sbt-sonatype/pull/458)
- Update airframe-http, airspec to 23.12.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/459](https://togithub.com/xerial/sbt-sonatype/pull/459)
- Update airframe-http, airspec to 23.12.1 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/460](https://togithub.com/xerial/sbt-sonatype/pull/460)
- Update airframe-http, airspec to 24.1.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/462](https://togithub.com/xerial/sbt-sonatype/pull/462)
- Update airframe-http, airspec to 24.1.1 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/463](https://togithub.com/xerial/sbt-sonatype/pull/463)
- Update airframe-http, airspec to 24.1.2 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/466](https://togithub.com/xerial/sbt-sonatype/pull/466)
- Bump release-drafter/release-drafter from 5 to 6 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/xerial/sbt-sonatype/pull/467](https://togithub.com/xerial/sbt-sonatype/pull/467)
- Update scalafmt-core to 3.8.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/468](https://togithub.com/xerial/sbt-sonatype/pull/468)
- Update airframe-http, airspec to 24.2.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/469](https://togithub.com/xerial/sbt-sonatype/pull/469)
- Update sbt, scripted-plugin to 1.9.9 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/470](https://togithub.com/xerial/sbt-sonatype/pull/470)
- Update airframe-http, airspec to 24.2.1 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/471](https://togithub.com/xerial/sbt-sonatype/pull/471)
- Update airframe-http, airspec to 24.2.2 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/472](https://togithub.com/xerial/sbt-sonatype/pull/472)
- Update scala-library to 2.12.19 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/473](https://togithub.com/xerial/sbt-sonatype/pull/473)
- Update airframe-http, airspec to 24.2.3 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/475](https://togithub.com/xerial/sbt-sonatype/pull/475)
- Update airframe-http, airspec to 24.3.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/476](https://togithub.com/xerial/sbt-sonatype/pull/476)
- Update scalafmt-core to 3.8.1 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/478](https://togithub.com/xerial/sbt-sonatype/pull/478)
- Update airframe-http, airspec to 24.4.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/479](https://togithub.com/xerial/sbt-sonatype/pull/479)
- Update airframe-http, airspec to 24.4.1 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/480](https://togithub.com/xerial/sbt-sonatype/pull/480)
- Update airframe-http, airspec to 24.4.2 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/481](https://togithub.com/xerial/sbt-sonatype/pull/481)
- Update airframe-http, airspec to 24.4.3 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/482](https://togithub.com/xerial/sbt-sonatype/pull/482)
- Update sbt, scripted-plugin to 1.10.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/484](https://togithub.com/xerial/sbt-sonatype/pull/484)
- Update airframe-http, airspec to 24.5.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/485](https://togithub.com/xerial/sbt-sonatype/pull/485)
- Update airframe-http, airspec to 24.5.1 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/486](https://togithub.com/xerial/sbt-sonatype/pull/486)
- Update airframe-http, airspec to 24.5.2 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/487](https://togithub.com/xerial/sbt-sonatype/pull/487)
- Update airframe-http, airspec to 24.6.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/488](https://togithub.com/xerial/sbt-sonatype/pull/488)
- Update scalafmt-core to 3.8.2 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/489](https://togithub.com/xerial/sbt-sonatype/pull/489)
- Update airframe-http, airspec to 24.6.1 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/490](https://togithub.com/xerial/sbt-sonatype/pull/490)

##### 🛠  Internal Updates

- Update sbt-sonatype to 3.10.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/455](https://togithub.com/xerial/sbt-sonatype/pull/455)
- Update sbt-buildinfo to 0.12.0 by
[@&#8203;xerial-bot](https://togithub.com/xerial-bot) in
[https://github.com/xerial/sbt-sonatype/pull/477](https://togithub.com/xerial/sbt-sonatype/pull/477)

##### Other Changes

- feature: Give helpful advice when profile missing on host by
[@&#8203;rtyley](https://togithub.com/rtyley) in
[https://github.com/xerial/sbt-sonatype/pull/461](https://togithub.com/xerial/sbt-sonatype/pull/461)

#### New Contributors

- [@&#8203;Andrapyre](https://togithub.com/Andrapyre) made their first
contribution in
[https://github.com/xerial/sbt-sonatype/pull/474](https://togithub.com/xerial/sbt-sonatype/pull/474)

**Full Changelog**:
xerial/sbt-sonatype@v3.10.0...v3.11.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log [here](https://developer.mend.io/github/slick/slick).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MTMuMiIsInVwZGF0ZWRJblZlciI6IjM3LjQxMy4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants