Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remoce surface message param
  • Loading branch information
jgonz120 committed Dec 12, 2023
commit e6219c5233e5271e91727421e4113f158689cd33
8 changes: 1 addition & 7 deletions src/NuGet.Core/NuGet.ProjectModel/FileFormatException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace NuGet.ProjectModel
{
public class FileFormatException : Exception
{
static internal string SurfaceMessage = "SurfaceMessage";

public FileFormatException(string message)
: base(message)
{
Expand Down Expand Up @@ -128,11 +126,7 @@ internal static FileFormatException Create(JsonReaderException exception, string
internal static FileFormatException Create(System.Text.Json.JsonException exception, string path)
{
string message;
if (exception.Data.Contains(SurfaceMessage))
{
message = exception.Message;
}
else if (exception.BytePositionInLine is not null && exception.LineNumber is not null)
if (exception.BytePositionInLine is not null && exception.LineNumber is not null)
{
message = string.Format(CultureInfo.CurrentCulture,
Strings.Log_ErrorReadingProjectJsonWithLocation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ internal static void ReadCentralTransitiveDependencyGroup(
var propertyName = jsonReader.GetString();
if (string.IsNullOrEmpty(propertyName))
{
var exception = new JsonException("Unable to resolve dependency ''.");
exception.Data.Add(FileFormatException.SurfaceMessage, true);
throw exception;
throw new JsonException("Unable to resolve dependency ''.");
}

if (jsonReader.Read())
Expand Down Expand Up @@ -418,9 +416,7 @@ private static void ReadDependencies(
var propertyName = jsonReader.GetString();
if (string.IsNullOrEmpty(propertyName))
{
var exception = new JsonException("Unable to resolve dependency ''.");
exception.Data.Add(FileFormatException.SurfaceMessage, true);
throw exception;
throw new JsonException("Unable to resolve dependency ''.");
}

// Support
Expand Down Expand Up @@ -1292,12 +1288,10 @@ private static void ReadPackageTypes(PackageSpec packageSpec, ref Utf8JsonStream
{
if (jsonReader.TokenType != JsonTokenType.String)
{
var exception = new JsonException(string.Format(
throw new JsonException(string.Format(
CultureInfo.CurrentCulture,
Strings.InvalidPackageType,
PackageSpec.PackageSpecFileName));
exception.Data.Add(FileFormatException.SurfaceMessage, true);
throw exception;
}

packageType = CreatePackageType(ref jsonReader);
Expand All @@ -1324,12 +1318,10 @@ private static void ReadPackageTypes(PackageSpec packageSpec, ref Utf8JsonStream
}
catch (Exception)
{
var exception = new JsonException(string.Format(
throw new JsonException(string.Format(
CultureInfo.CurrentCulture,
Strings.InvalidPackageType,
PackageSpec.PackageSpecFileName));
exception.Data.Add(FileFormatException.SurfaceMessage, true);
throw exception;
}
}

Expand Down Expand Up @@ -1579,9 +1571,7 @@ private static void ReadScripts(ref Utf8JsonStreamReader jsonReader, PackageSpec
}
else
{
var exception = new JsonException(string.Format(CultureInfo.CurrentCulture, "The value of a script in '{0}' can only be a string or an array of strings", PackageSpec.PackageSpecFileName));
exception.Data.Add(FileFormatException.SurfaceMessage, true);
throw exception;
throw new JsonException(string.Format(CultureInfo.CurrentCulture, "The value of a script in '{0}' can only be a string or an array of strings", PackageSpec.PackageSpecFileName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1176,8 +1176,7 @@ public void GetPackageSpec_WhenDependenciesDependencyNameIsEmptyString_Throws()
const string json = "{\"dependencies\":{\"\":{}}}";

FileFormatException exception = Assert.Throws<FileFormatException>(() => GetPackageSpec(json));

Assert.Equal("Unable to resolve dependency ''.", exception.Message);
Assert.Equal("Error reading '' : Unable to resolve dependency ''.", exception.Message);
}

[Fact]
Expand Down Expand Up @@ -1660,7 +1659,7 @@ public void GetPackageSpec_WhenFrameworksDependenciesDependencyNameIsEmptyString

FileFormatException exception = Assert.Throws<FileFormatException>(() => GetPackageSpec(json));

Assert.Equal("Unable to resolve dependency ''.", exception.Message);
Assert.Equal("Error reading '' : Unable to resolve dependency ''.", exception.Message);
Assert.IsType<System.Text.Json.JsonException>(exception.InnerException);
Assert.Null(exception.InnerException.InnerException);
}
Expand Down Expand Up @@ -2493,7 +2492,7 @@ public void GetPackageSpec_WhenPackOptionsPackageTypeIsInvalid_Throws(string val

FileFormatException exception = Assert.Throws<FileFormatException>(() => GetPackageSpec(json));

Assert.Equal("The pack options package type must be a string or array of strings in 'project.json'.", exception.Message);
Assert.Equal("Error reading '' : The pack options package type must be a string or array of strings in 'project.json'.", exception.Message);
Assert.IsType<System.Text.Json.JsonException>(exception.InnerException);
Assert.Null(exception.InnerException.InnerException);
}
Expand Down Expand Up @@ -3363,7 +3362,7 @@ public void GetPackageSpec_WhenScriptsValueIsInvalid_Throws()

FileFormatException exception = Assert.Throws<FileFormatException>(() => GetPackageSpec(json));

Assert.Equal("The value of a script in 'project.json' can only be a string or an array of strings", exception.Message);
Assert.Equal("Error reading '' : The value of a script in 'project.json' can only be a string or an array of strings", exception.Message);
Assert.IsType<System.Text.Json.JsonException>(exception.InnerException);
Assert.Null(exception.InnerException.InnerException);

Expand Down