Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

### Build tool

- The build tool now prints a better error message when the user does not have
permission to publish a package which already exists on Hex.
([Surya Rose](https://github.com/GearsDatapacks))

## v1.14.0-rc3 - 2025-12-21

### Bug fixes
Expand Down
1 change: 1 addition & 0 deletions compiler-cli/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn command(paths: &ProjectPaths, replace: bool, i_am_sure: bool) -> Result<(
cli::print_publishing(&config.name, &config.version);

runtime.block_on(hex::publish_package(
&config.name,
package_tarball,
config.version.to_string(),
&api_key,
Expand Down
16 changes: 16 additions & 0 deletions compiler-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ file_names.iter().map(|x| x.as_str()).join(", "))]
#[error("Version already published")]
HexPublishReplaceRequired { version: String },

#[error("No permission to publish package")]
HexPublishForbidden { version: String, package: EcoString },

#[error("The gleam version constraint is wrong and so cannot be published")]
CannotPublishWrongVersion {
minimum_required_version: SmallVersion,
Expand Down Expand Up @@ -4584,6 +4587,19 @@ or you can publish it using a different version number"
),
}],

Error::HexPublishForbidden { package, version } => vec![Diagnostic {
title: "No permission to publish package".into(),
text: wrap_format!(
"I couldn't publish v{version} of {package}. That name is \
already taken on hex and you don't have permission to publish it."
),
level: Level::Error,
location: None,
hint: Some(format!(
"Choose a new name or make sure you are authorised to publish {package}."
)),
}],

Error::CannotAddSelfAsDependency { name } => vec![Diagnostic {
title: "Dependency cycle".into(),
text: wrap_format!(
Expand Down
5 changes: 5 additions & 0 deletions compiler-core/src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn key_name(hostname: &str) -> String {
}

pub async fn publish_package<Http: HttpClient>(
name: &ecow::EcoString,
release_tarball: Vec<u8>,
version: String,
api_key: &str,
Expand All @@ -40,6 +41,10 @@ pub async fn publish_package<Http: HttpClient>(
let response = http.send(request).await?;
hexpm::api_publish_package_response(response).map_err(|e| match e {
ApiError::NotReplacing => Error::HexPublishReplaceRequired { version },
ApiError::Forbidden => Error::HexPublishForbidden {
version,
package: name.clone(),
},
err => Error::hex(err),
})
}
Expand Down
Loading