This repository has been archived by the owner on Dec 18, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ProjectFormatException and more detailed errors to DTH
- ProjectFormatException has the project path, line and Column (1 based), where the exception ocurred in the project.json file. - Give more specific errors when they aren't just JsonReaderExceptions, but semantic exceptions within the project format itself (beyond just JSON). - Added Path, Line and Column to ErrorMessage in DTH #1052
- Loading branch information
Showing
4 changed files
with
157 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.Framework.Runtime | ||
{ | ||
public sealed class ProjectFormatException : Exception | ||
{ | ||
public ProjectFormatException(string message) : | ||
base(message) | ||
{ | ||
} | ||
|
||
public ProjectFormatException(string message, Exception innerException) : | ||
base(message, innerException) | ||
{ | ||
|
||
} | ||
|
||
public string Path { get; private set; } | ||
public int Line { get; private set; } | ||
public int Column { get; private set; } | ||
|
||
private ProjectFormatException WithLineInfo(IJsonLineInfo lineInfo) | ||
{ | ||
Line = lineInfo.LineNumber; | ||
Column = lineInfo.LinePosition; | ||
|
||
return this; | ||
} | ||
|
||
public static ProjectFormatException Create(Exception exception, JToken value, string path) | ||
{ | ||
var lineInfo = (IJsonLineInfo)value; | ||
|
||
return new ProjectFormatException(exception.Message, exception) | ||
{ | ||
Path = path | ||
} | ||
.WithLineInfo(lineInfo); | ||
} | ||
|
||
public static ProjectFormatException Create(string message, JToken value, string path) | ||
{ | ||
var lineInfo = (IJsonLineInfo)value; | ||
|
||
return new ProjectFormatException(message) | ||
{ | ||
Path = path | ||
} | ||
.WithLineInfo(lineInfo); | ||
} | ||
|
||
internal static ProjectFormatException Create(JsonReaderException exception, string path) | ||
{ | ||
return new ProjectFormatException(exception.Message, exception) | ||
{ | ||
Path = path, | ||
Column = exception.LineNumber, | ||
Line = exception.LinePosition | ||
}; | ||
} | ||
} | ||
} |