Skip to content

Commit

Permalink
OpenXMLFile return value for not existing files or parsing errors (#463)
Browse files Browse the repository at this point in the history
* OpenXMLFile: return error if file does not exist instead of xmlobject in
error state

* added docs

* translate every xml open/parsing error to BError

* updated core changes entry, to reflect the latest changes
  • Loading branch information
turleypol committed Jun 21, 2022
1 parent 458356f commit 737db93
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
8 changes: 7 additions & 1 deletion docs/docs.polserver.com/pol100/corechanges.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
<ESCRIPT>
<header>
<topic>Latest Core Changes</topic>
<datemodified>06-16-2022</datemodified>
<datemodified>06-21-2022</datemodified>
</header>
<version name="POL100.1.0">
<entry>
<date>06-21-2022</date>
<author>Turley:</author>
<change type="Changed">OpenXMLFile(file) returns Error if file does not exists, or any parsing error occurs.<br/>
Before it returned XMLRef in an error state, so 'if (!xml)' was and is a way to check for success.</change>
</entry>
<entry>
<date>06-16-2022</date>
<author>Kevin:</author>
Expand Down
3 changes: 3 additions & 0 deletions pol-core/doc/core-changes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
-- POL100.1.0 --
06-21-2022 Turley:
Changed: OpenXMLFile(file) returns Error if file does not exists, or any parsing error occurs.
Before it returned XMLRef in an error state, so 'if (!xml)' was and is a way to check for success.
06-16-2022 Kevin:
Fixed: Corrected objref documentation on Character.acct, Character.acctname, and Client.acctname.
Added: client.acct member to return Account object
Expand Down
8 changes: 6 additions & 2 deletions pol-core/pol/module/filemod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,12 @@ Bscript::BObjectImp* FileAccessExecutorModule::mf_OpenXMLFile()
filepath = path;
else
filepath = outpkg->dir() + path;

return new Core::BXMLfile( filepath );
if ( !Clib::FileExists( filepath ) )
return new BError( "File does not exist" );
std::unique_ptr<Core::BXMLfile> xml( new Core::BXMLfile( filepath ) );
if ( !xml->isTrue() )
return new BError( xml->getStringRep() );
return xml.release();
}

Bscript::BObjectImp* FileAccessExecutorModule::mf_CreateXMLFile()
Expand Down
4 changes: 4 additions & 0 deletions testsuite/escript/filemod/xml.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ attributes= 2
scopetest...
root= root
firstchild= Hello
not existing file...
Error
invalid file...
Error
15 changes: 15 additions & 0 deletions testsuite/escript/filemod/xml.src
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ program XMLTest()
membertest();
print("scopetest...");
scopetest();
print("not existing file...");
notexistingtest();
print("invalid file...");
invalidtest();
endprogram

function itertest()
Expand Down Expand Up @@ -51,3 +55,14 @@ function scopeloose()
var xml:=OpenXMLFile("filemod/xmltest.xml");
return xml[2].clonenode();
endfunction


function notexistingtest()
var xml:=OpenXMLFile("filemod/xmltestnotexisting.xml");
print(typeof(xml));
endfunction

function invalidtest()
var xml:=OpenXMLFile("filemod/xmlinvalid.xml");
print(typeof(xml));
endfunction
4 changes: 4 additions & 0 deletions testsuite/escript/filemod/xmlinvalid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" ?>
<root>
<Hello>World</He>
</root>

0 comments on commit 737db93

Please sign in to comment.