Skip to content

[FileFormats.NL] improve error msg when parsing unhandled headers #2436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
"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
end

function _parse_section(::IO, ::Val{'V'}, ::_CacheModel)
return error(
"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(
"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