Skip to content

Commit 1f37525

Browse files
committed
gleam update should return error if package does not exists
1 parent 60e36fe commit 1f37525

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,7 @@
428428
- The compiler now provides a clearer error message when a function's return type
429429
is mistakenly declared using `:` instead of `->`.
430430
([Gurvir Singh](https://github.com/baraich))
431+
432+
- Added an error message when attempting to update packages that are not dependencies
433+
of the project, instead of failing silently.
434+
([Etienne Boutet](https://github.com/EtienneBoutet)) and ([Vladislav Shakitskiy](https://github.com/vshakitskiy))

compiler-cli/src/dependencies/dependency_manager.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ where
8181
if !paths.manifest().exists() {
8282
tracing::debug!("manifest_not_present");
8383
let manifest = self.perform_version_resolution(paths, config, None, Vec::new())?;
84+
self.ensure_packages_exist_locally(&manifest, packages_to_update.clone())?;
8485
return Ok(Resolved::all_added(manifest));
8586
}
8687

8788
let existing_manifest = read_manifest_from_disc(paths)?;
89+
self.ensure_packages_exist_locally(&existing_manifest, packages_to_update.clone())?;
8890

8991
// If we have been asked not to use the manifest then
9092
let (requirements_changed, manifest_for_resolver) = match self.use_manifest {
@@ -123,6 +125,25 @@ where
123125
Ok(resolved)
124126
}
125127

128+
fn ensure_packages_exist_locally(
129+
&self,
130+
manifest: &Manifest,
131+
packages: Vec<EcoString>,
132+
) -> Result<()> {
133+
let missing_packages: Vec<String> = packages
134+
.iter()
135+
.filter(|package_name| !manifest.packages.iter().any(|p| &p.name == *package_name))
136+
.map(|eco| eco.to_string())
137+
.collect();
138+
139+
if !missing_packages.is_empty() {
140+
return Err(Error::PackagesToUpdateNotExist {
141+
packages: missing_packages,
142+
});
143+
}
144+
Ok(())
145+
}
146+
126147
pub fn resolve_and_download_versions(
127148
&self,
128149
paths: &ProjectPaths,

compiler-core/src/error.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ file_names.iter().map(|x| x.as_str()).join(", "))]
205205
#[error("Packages not exist: {}", packages.iter().join(", "))]
206206
RemovedPackagesNotExist { packages: Vec<String> },
207207

208+
#[error("Packages to update not exist: {}", packages.iter().join(", "))]
209+
PackagesToUpdateNotExist { packages: Vec<String> },
210+
208211
#[error("unable to find project root")]
209212
UnableToFindProjectRoot { path: String },
210213

@@ -1001,6 +1004,24 @@ If you want to overwrite these files, delete them and run the command again.
10011004
"These packages are not dependencies of your package so they could not
10021005
be removed.
10031006
1007+
{}
1008+
",
1009+
packages
1010+
.iter()
1011+
.map(|p| format!(" - {}", p.as_str()))
1012+
.join("\n")
1013+
),
1014+
level: Level::Error,
1015+
hint: None,
1016+
location: None,
1017+
}],
1018+
1019+
Error::PackagesToUpdateNotExist { packages } => vec![Diagnostic {
1020+
title: "Packages to update not found".into(),
1021+
text: format!(
1022+
"These packages are not dependencies of your package so they could not
1023+
be updated.
1024+
10041025
{}
10051026
",
10061027
packages

0 commit comments

Comments
 (0)