Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Log line numbers on schema validation errors #388

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
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
31 changes: 30 additions & 1 deletion XmlSchemaClassGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,14 @@ public void Generate(IEnumerable<string> files)
var ex = e.Exception as Exception;
while (ex != null)
{
Log?.Invoke(ex.Message);
if(ex is XmlSchemaException xmlException)
{
Log?.Invoke(FormatXmlSchemaExeption(xmlException));
}
else
{
Log?.Invoke(ex.Message);
}
ex = ex.InnerException;
}
};
Expand Down Expand Up @@ -378,5 +385,27 @@ public void Generate(XmlSchemaSet set)
writer.Write(ns);
}
}

private string FormatXmlSchemaExeption(XmlSchemaException e)
{
StringBuilder sb = new StringBuilder(e.Message);

if(!string.IsNullOrEmpty(e.SourceUri))
{
sb.AppendFormat(" at {0}:{1}:{2}",
e.SourceUri,
e.LineNumber,
e.LinePosition);
}
else if(e.SourceSchemaObject != null)
{
sb.AppendFormat(" at {0}:{1}:{2}",
e.SourceSchemaObject.SourceUri,
e.SourceSchemaObject.LineNumber,
e.SourceSchemaObject.LinePosition);
}

return sb.ToString();
}
}
}