Skip to content

Commit 1eab079

Browse files
pontaGCpontaGC
andauthored
fix unhandled error occurs when loading a file with invalid XML format in the schema dialog. (#438)
Co-authored-by: pontaGC <makizawawa@gmail.com>
1 parent 08e1a3a commit 1eab079

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

src/Application/FormSchemas.cs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -796,22 +796,36 @@ public XmlSchema ValidateSchema(DataGridViewRow row, string filename)
796796
public XmlSchema LoadSchema(string filename)
797797
{
798798
if (string.IsNullOrEmpty(filename)) return null;
799-
using (var r = new XmlTextReader(filename, new NameTable()))
799+
try
800800
{
801-
return XmlSchema.Read(r, (sender, args) =>
801+
using (var r = new XmlTextReader(filename, new NameTable()))
802802
{
803-
if (args.Exception is XmlSchemaException se)
803+
return XmlSchema.Read(r, (sender, args) =>
804804
{
805-
LogError($"{args.Message} See line {se.LineNumber} pos {se.LinePosition} of {se.SourceUri}");
806-
}
807-
else
808-
{
809-
LogError(args.Message);
810-
}
811-
});
805+
if (args.Exception is XmlSchemaException se)
806+
{
807+
this.LogError($"{args.Message} See line {se.LineNumber} pos {se.LinePosition} of {se.SourceUri}");
808+
}
809+
else
810+
{
811+
this.LogError(args.Message);
812+
}
813+
});
814+
}
815+
}
816+
catch (XmlException xe)
817+
{
818+
// The files that do not meet the basic XML structure,
819+
// such as empty files or files with unclosed tags
820+
this.LogError($"{xe.Message} See line {xe.LineNumber} pos {xe.LinePosition} of {xe.SourceUri}");
821+
return null;
822+
}
823+
catch (Exception e)
824+
{
825+
this.LogError(e.Message);
826+
return null;
812827
}
813828
}
814-
815829
}
816830

817831
class SchemaDialogNewRow : SchemaDialogCommand

0 commit comments

Comments
 (0)