this repo has no description

Error for invalid dependency specification

Closes https://github.com/gleam-lang/gleam/issues/4867

+40 -9
+5
CHANGELOG.md
··· 261 261 dependencies to be imported. 262 262 ([Surya Rose](https://github.com/GearsDatapacks)) 263 263 264 + - Erroneous extra fields in `gleam.toml` dependency specifications will no 265 + longer be siltently ignored. An error is now returned highlighting the 266 + problem instead. 267 + ([Louis Pilfold](https://github.com/lpil)) 268 + 264 269 - Fixed a bug where renaming a constant which is referenced in another module 265 270 inside a guard would generate invalid code. 266 271 ([Surya Rose](https://github.com/GearsDatapacks))
+32 -7
compiler-core/src/config.rs
··· 218 218 fs: &FS, 219 219 ) -> Result<PackageConfig, Error> { 220 220 let toml = fs.read(path.as_ref())?; 221 - let config: PackageConfig = toml::from_str(&toml).map_err(|e| Error::FileIo { 222 - action: FileIoAction::Parse, 223 - kind: FileKind::File, 224 - path: path.as_ref().to_path_buf(), 225 - err: Some(e.to_string()), 226 - })?; 227 - Ok(config) 221 + deserialise_config(path, toml) 228 222 } 229 223 230 224 /// Get the locked packages for the current config and a given (optional) ··· 320 314 None => format!("v{version}"), 321 315 } 322 316 } 317 + } 318 + 319 + fn deserialise_config<P: AsRef<Utf8Path>>( 320 + path: P, 321 + toml: String, 322 + ) -> std::result::Result<PackageConfig, Error> { 323 + let config: PackageConfig = toml::from_str(&toml).map_err(|e| Error::FileIo { 324 + action: FileIoAction::Parse, 325 + kind: FileKind::File, 326 + path: path.as_ref().to_path_buf(), 327 + err: Some(e.to_string()), 328 + })?; 329 + Ok(config) 330 + } 331 + 332 + // https://github.com/gleam-lang/gleam/issues/4867 333 + #[test] 334 + fn deny_extra_deps_properties() { 335 + let toml = r#" 336 + name = "wibble" 337 + version = "1.0.0" 338 + 339 + [dependencies] 340 + aide_generator = { git = "git@github.com:crowdhailer/aide.git", ref = "f559c5bc", extra = "idk what this is" } 341 + "#; 342 + let error = deserialise_config("gleam.toml", toml.into()) 343 + .expect_err("should fail to deserialise because of additional path"); 344 + assert_eq!( 345 + error.to_string(), 346 + r#"Parse "gleam.toml" failed: Some("data did not match any variant of untagged enum Requirement for key `dependencies.aide_generator` at line 6 column 18")"# 347 + ); 323 348 } 324 349 325 350 #[test]
+1 -1
compiler-core/src/error.rs
··· 115 115 #[error("cyclical package dependencies")] 116 116 PackageCycle { packages: Vec<EcoString> }, 117 117 118 - #[error("file operation failed")] 118 + #[error("{action:?} {path:?} failed: {err:?}")] 119 119 FileIo { 120 120 kind: FileKind, 121 121 action: FileIoAction,
+2 -1
compiler-core/src/requirement.rs
··· 12 12 use serde::ser::{Serialize, SerializeMap, Serializer}; 13 13 14 14 #[derive(Deserialize, Debug, PartialEq, Eq, Clone)] 15 - #[serde(untagged, remote = "Self")] 15 + #[serde(untagged, remote = "Self", deny_unknown_fields)] 16 16 pub enum Requirement { 17 17 Hex { 18 18 #[serde(deserialize_with = "deserialise_range")] 19 19 version: Range, 20 20 }, 21 + 21 22 Path { 22 23 path: Utf8PathBuf, 23 24 },