Skip to content

Commit

Permalink
[FileFormats.NL] improve error msg when parsing unhandled headers
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Feb 20, 2024
1 parent e8ce0c2 commit bb38ef6
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/FileFormats/NL/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,44 @@ function _parse_section(::IO, ::Val{T}, ::_CacheModel) where {T}
return error("Unable to parse NL file: unhandled header $T")
end

function _parse_section(::IO, ::Val{'F'}, ::_CacheModel)
return error(

Check warning on line 376 in src/FileFormats/NL/read.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/NL/read.jl#L375-L376

Added lines #L375 - L376 were not covered by tests
"Unable to parse NL file: imported function descriptions ('F' " *
"sections) are not yet supported. To request support, please open an " *
"issue at https://github.com/jump-dev/MathOptInterface.jl with a " *
"reproducible example.",
)
end

function _parse_section(io::IO, ::Val{'S'}, model::_CacheModel)
k = _next(Int, io, model)
n = _next(Int, io, model)
suffix = readline(io)
@warn("Skipping suffix: `S$k $n$suffix`")
for _ in 1:n
_read_til_newline(io)
end
return

Check warning on line 392 in src/FileFormats/NL/read.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/NL/read.jl#L384-L392

Added lines #L384 - L392 were not covered by tests
end

function _parse_section(::IO, ::Val{'V'}, ::_CacheModel)
return error(

Check warning on line 396 in src/FileFormats/NL/read.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/NL/read.jl#L395-L396

Added lines #L395 - L396 were not covered by tests
"Unable to parse NL file: defined variable definitions ('V' sections)" *
" are not yet supported. To request support, please open an issue at " *
"https://github.com/jump-dev/MathOptInterface.jl with a reproducible " *
"example.",
)
end

function _parse_section(::IO, ::Val{'L'}, ::_CacheModel)
return error(

Check warning on line 405 in src/FileFormats/NL/read.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/NL/read.jl#L404-L405

Added lines #L404 - L405 were not covered by tests
"Unable to parse NL file: logical constraints ('L' sections) are not " *
"yet supported. To request support, please open an issue at " *
"https://github.com/jump-dev/MathOptInterface.jl with a reproducible " *
"example.",
)
end

function _parse_section(io::IO, ::Val{'C'}, model::_CacheModel)
index = _next(Int, io, model) + 1
_read_til_newline(io)
Expand Down
77 changes: 77 additions & 0 deletions test/FileFormats/NL/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,83 @@ v1
return
end

function test_parse_F()
model = NL._CacheModel()
io = IOBuffer()
write(io, "F")
seekstart(io)
@test_throws(
ErrorException(
"Unable to parse NL file: imported function descriptions ('F' " *
"sections) are not yet supported. To request support, please open an " *
"issue at https://github.com/jump-dev/MathOptInterface.jl with a " *
"reproducible example.",
),
NL._parse_section(io, model),
)
return
end

function test_parse_V()
model = NL._CacheModel()
io = IOBuffer()
write(io, "V")
seekstart(io)
@test_throws(
ErrorException(
"Unable to parse NL file: defined variable definitions ('V' sections)" *
" are not yet supported. To request support, please open an issue at " *
"https://github.com/jump-dev/MathOptInterface.jl with a reproducible " *
"example.",
),
NL._parse_section(io, model),
)
return
end

function test_parse_L()
model = NL._CacheModel()
io = IOBuffer()
write(io, "L")
seekstart(io)
@test_throws(
ErrorException(
"Unable to parse NL file: logical constraints ('L' sections) are not " *
"yet supported. To request support, please open an issue at " *
"https://github.com/jump-dev/MathOptInterface.jl with a reproducible " *
"example.",
),
NL._parse_section(io, model),
)
return
end

function test_parse_S()
model = NL._CacheModel()
io = IOBuffer()
write(
io,
"""
S0 8 zork
02
16
27
38
49
53
65
84
""",
)
seekstart(io)
@test_logs(
(:warn, "Skipping suffix: `S0 8 zork`"),
NL._parse_section(io, model),
)
@test eof(io)
return
end

function test_hs071()
model = NL.Model()
open(joinpath(@__DIR__, "data", "hs071.nl"), "r") do io
Expand Down

0 comments on commit bb38ef6

Please sign in to comment.