private void LogError(JsonError error) { IRule rule = GetRuleForError(error); Result result = MakeResultFromError(error); _logger.Log(rule, result); _messages.Add(result.FormatForVisualStudio(rule)); }
private static IRule GetRuleForError(JsonError error) { switch (error.Kind) { case JsonErrorKind.Syntax: return(JsonSyntaxErrorRule); case JsonErrorKind.Validation: return(JsonSchemaValidationErrorRule); default: return(UnknownErrorRule); } }
private Result MakeResultFromError(JsonError error) { var result = new Result(); string analysisTargetFilePath; NewLineIndex index = null; switch (error.Location) { case JsonErrorLocation.InstanceDocument: analysisTargetFilePath = _instanceFilePath; index = InstanceFileIndex; break; case JsonErrorLocation.Schema: analysisTargetFilePath = _schemaFilePath; index = SchemaFileIndex; break; default: analysisTargetFilePath = "unknown_file"; break; } Uri analysisTargetUri = new Uri(analysisTargetFilePath); switch (error.Kind) { case JsonErrorKind.Syntax: result.RuleId = JsonSyntaxErrorRule.Id; result.Kind = ResultKind.Error; result.FormattedRuleMessage = new FormattedRuleMessage { FormatId = JsonSyntaxErrorFormatSpecifier, Arguments = new[] { error.Message } }; break; case JsonErrorKind.Validation: result.RuleId = JsonSchemaValidationErrorRule.Id; result.Kind = ResultKind.Error; result.FormattedRuleMessage = new FormattedRuleMessage { FormatId = JsonSchemaValidationErrorFormatSpecifier, Arguments = new[] { error.Message } }; break; default: result.RuleId = UnknownErrorRule.Id; result.Kind = ResultKind.InternalError; result.FormattedRuleMessage = new FormattedRuleMessage { FormatId = UnknownErrorFormatSpecifier, Arguments = new string[] { error.Kind.ToString() } }; break; } Region region; if (index != null) { region = new Region { Offset = error.Start, Length = error.Length }; region.Populate(index); } else { region = new Region(); } var location = new Location { AnalysisTarget = new PhysicalLocation { Uri = analysisTargetUri, Region = region } }; result.Locations = new HashSet <Location> { location }; return(result); }