XLSX.jl icon indicating copy to clipboard operation
XLSX.jl copied to clipboard

Asserts should not be used for validation

Open jakewilliami opened this issue 2 years ago • 1 comments

I was having a look at the code (excellent package, by the way!), and noticed that you use @assert to validate certain data. In the future, Julia might be allowing a compiler flag to turn off asserts, so this might be best to refactor out into (perhaps custom) errors. (See JuliaLang#10614.)

jakewilliami avatar Mar 01 '22 19:03 jakewilliami

@felipenoris May I use this issue to include a strange AssertionError that I encountered during loading a particular xlsx-file.

ERROR: AssertionError: Unexpected namespace at relationship file: `["" => "http://schemas.openxmlformats.org/package/2006/relationships", "asx" => "http://www.sap.com/abapxml"]`.

The corresponding line of code (here and there) is

    @assert EzXML.namespaces(xroot) == Pair{String,String}[""=>"http://schemas.openxmlformats.org/package/2006/relationships"] "Unexpected namespace at relationship file: `$(EzXML.namespaces(xroot))`."

I'm not familiar with the relationships of the openxml format. But for me it was sufficient to change the code at the two above locations into

    @assert (""=>"http://schemas.openxmlformats.org/package/2006/relationships") ∈ EzXML.namespaces(xroot) "Unexpected namespace at workbook relationship file: `$(EzXML.namespaces(xroot))`."

to have my file loaded perfectly.

hhaensel avatar Dec 08 '23 09:12 hhaensel