Skip to content

Commit 567eece

Browse files
Merge pull request #745 from jimmylewis/missingVersionError
Add an error when the manifest is missing a version
2 parents 7e62d74 + 5ad3aee commit 567eece

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

src/LibraryManager.Contracts/PredefinedErrors.cs

+6
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ public static IError DuplicateLibrariesInManifest(string duplicateLibrary)
198198
public static IError FileNameMustNotBeEmpty(string libraryId)
199199
=> new Error("LIB020", string.Format(Text.ErrorFilePathIsEmpty, libraryId));
200200

201+
/// <summary>
202+
/// The manifest must specify a version
203+
/// </summary>
204+
public static IError MissingManifestVersion()
205+
=> new Error("LIB022", Text.ErrorMissingManifestVersion);
206+
201207
/// <summary>
202208
/// Unknown error occurred
203209
/// </summary>

src/LibraryManager.Contracts/Resources/Text.Designer.cs

+10-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LibraryManager.Contracts/Resources/Text.resx

+4-1
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,7 @@ Valid files are {2}</value>
187187
<data name="ErrorFilePathIsEmpty" xml:space="preserve">
188188
<value>The library "{0}" cannot specify a file with an empty name</value>
189189
</data>
190-
</root>
190+
<data name="ErrorMissingManifestVersion" xml:space="preserve">
191+
<value>The Library Manager manifest must specify a version.</value>
192+
</data>
193+
</root>

src/LibraryManager/LibrariesValidator.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,17 @@ public static async Task<IEnumerable<ILibraryOperationResult>> GetManifestErrors
8080

8181
if (manifest == null)
8282
{
83-
return new ILibraryOperationResult[] { LibraryOperationResult.FromError(PredefinedErrors.ManifestMalformed()) };
83+
return [LibraryOperationResult.FromError(PredefinedErrors.ManifestMalformed())];
84+
}
85+
86+
if (string.IsNullOrEmpty(manifest.Version))
87+
{
88+
return [LibraryOperationResult.FromError(PredefinedErrors.MissingManifestVersion())];
8489
}
8590

8691
if (!IsValidManifestVersion(manifest.Version))
8792
{
88-
return new ILibraryOperationResult[] { LibraryOperationResult.FromError(PredefinedErrors.VersionIsNotSupported(manifest.Version)) };
93+
return [LibraryOperationResult.FromError(PredefinedErrors.VersionIsNotSupported(manifest.Version))];
8994
}
9095

9196
return await GetLibrariesErrorsAsync(manifest.Libraries, dependencies, manifest.DefaultDestination, manifest.DefaultProvider, cancellationToken);

test/LibraryManager.Test/ManifestTest.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public async Task RestoreAsync_AllRestoreOperationsCancelled()
235235
}
236236

237237
[TestMethod]
238-
public async Task RestorAsync_ConflictingLibraries_Validate()
238+
public async Task RestoreAsync_ConflictingLibraries_Validate()
239239
{
240240
var manifest = Manifest.FromJson(_docConflictingLibraries, _dependencies);
241241

@@ -246,7 +246,7 @@ public async Task RestorAsync_ConflictingLibraries_Validate()
246246
}
247247

248248
[TestMethod]
249-
public async Task RestorAsync_ConflictingLibraries_Restore()
249+
public async Task RestoreAsync_ConflictingLibraries_Restore()
250250
{
251251
var manifest = Manifest.FromJson(_docConflictingLibraries, _dependencies);
252252

@@ -263,6 +263,19 @@ public void FromJson_Malformed()
263263
Assert.IsNull(manifest);
264264
}
265265

266+
[TestMethod]
267+
public async Task FromJson_MissingManifestVersion()
268+
{
269+
var manifest = Manifest.FromJson("{}", _dependencies);
270+
271+
List<ILibraryOperationResult> result = (await manifest.GetValidationResultsAsync(CancellationToken.None)).ToList();
272+
273+
Assert.AreEqual(1, result.Count);
274+
Assert.IsFalse(result[0].Success);
275+
Assert.AreEqual(1, result[0].Errors.Count);
276+
Assert.AreEqual("LIB022", result[0].Errors[0].Code);
277+
}
278+
266279
[TestMethod]
267280
public async Task FromFileAsync_FileNotFound()
268281
{

0 commit comments

Comments
 (0)