Inconsistent error handling of TfrReport.LoadFromFile
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
The error handling when trying to LoadFromFile a Lazreport file is rather inconsistent.
LoadFromFile() does not give any error when trying to read a non-existing file with .lrf extension.
When LoadFromFile encounters an error, it either raises an exception (this is good), or it shows a
hard-coded message dialog "Unsupported FRF format". This is bad, because the
programmer of the application now does not know that an error has occurred, because LoadFromFile returns normally.
The behaviour is inconsistent when compared with other LCL components that have a LoadFromFile() functionality (Anything with TStrings, TStringGrid), but that may be a matter of taste.
Having a hard-coded MessageDlg in this function IMHO is also bad design:
the fuctionality of the component should be separated from how errors are presented in the GUI
Steps to reproduce:
Unzip, build and run the attached sampleproject and click on the button.
The test tries to read the following files:
'non-existing.lrf' : this file does not exist
'non-existing.foo' : this file does not exist
'empty' : an empty file (it behaves the same when it contains simple text)
'empty.lrf' : an empty file (it behaves the same when it contains simple text)
'valid.lrf' : a valid LazReport .lrf file, as created by Lazarus on an unrelated project
'valid_lrf.foo' : a copy of valid.lrf
'invalid.lrf' : a copy of valid.lrf, but the tags &LtPos;LazReport> is replaced with &LtPos;LReport>, so technically it is not a valid LazRport anymore
'valid.xml' : a sample xml file
'valid_xml.foo' : a copy of valid.xml
'invalid.xml' : an xml file with broken syntax
Test results:
--------------------------------------------------
Trying to open file: non-existing.lrf -> SUCCESS
//Expected some kind of excpetion
--------------------------------------------------
--------------------------------------------------
Trying to open file: non-existing.foo
Exception caught of type EFOpenError
Message = "Unable to open file "non-existing.foo""
--------------------------------------------------
--------------------------------------------------
Trying to open file: empty -> SUCCESS
//Expected "Unsupported FRF format"
--------------------------------------------------
--------------------------------------------------
Trying to open file: empty.lrf
Exception caught of type EXMLReadError
Message = "In 'file:empty.lrf' (line 2 pos 1): Root element is missing"
--------------------------------------------------
--------------------------------------------------
Trying to open file: valid.lrf -> SUCCESS
--------------------------------------------------
--------------------------------------------------
Trying to open file: valid_lrf.foo -> SUCCESS
// Shows the "Unsupported FRF format" dialog
(before writing 'SUCCESS to the console)
// Expected no problem
--------------------------------------------------
--------------------------------------------------
Trying to open file: invalid.lrf -> SUCCESS
// Expected "Unsupported FRF format"
--------------------------------------------------
--------------------------------------------------
Trying to open file: valid.xml -> SUCCESS
// Shows the "Unsupported FRF format" dialog
(before writing 'SUCCESS to the console)
--------------------------------------------------
--------------------------------------------------
Trying to open file: valid_xml.foo -> SUCCESS
// Shows the "Unsupported FRF format" dialog
(before writing 'SUCCESS to the console)
--------------------------------------------------
--------------------------------------------------
Trying to open file: invalid.xml -> SUCCESS
// Shows the "Unsupported FRF format" dialog
(before writing 'SUCCESS to the console)
--------------------------------------------------
Additional information:
The test also has several memory leaks (see leaks.txt, it's in the lr.zip), but these may a user error on my side (maybe they can be avoided, but ATM I just don't know how).
Mantis conversion info:
- Mantis ID: 26636
- OS: Window
- OS Build: Win7
- Build: r46073
- Platform: i386
- Version: 1.3 (SVN)
- Fixed in version: 1.3 (SVN)
- Fixed in revision: 46085 (#3d577597)
- Target version: 1.4