Skip to content

Commit 50a1284

Browse files
authored
[FileFormats.NL] improve error msg when parsing unhandled headers (#2436)
1 parent e8ce0c2 commit 50a1284

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

src/FileFormats/NL/read.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,44 @@ function _parse_section(::IO, ::Val{T}, ::_CacheModel) where {T}
372372
return error("Unable to parse NL file: unhandled header $T")
373373
end
374374

375+
function _parse_section(::IO, ::Val{'F'}, ::_CacheModel)
376+
return error(
377+
"Unable to parse NL file: imported function descriptions ('F' " *
378+
"sections) are not yet supported. To request support, please open an " *
379+
"issue at https://github.com/jump-dev/MathOptInterface.jl with a " *
380+
"reproducible example.",
381+
)
382+
end
383+
384+
function _parse_section(io::IO, ::Val{'S'}, model::_CacheModel)
385+
k = _next(Int, io, model)
386+
n = _next(Int, io, model)
387+
suffix = readline(io)
388+
@warn("Skipping suffix: `S$k $n$suffix`")
389+
for _ in 1:n
390+
_read_til_newline(io)
391+
end
392+
return
393+
end
394+
395+
function _parse_section(::IO, ::Val{'V'}, ::_CacheModel)
396+
return error(
397+
"Unable to parse NL file: defined variable definitions ('V' sections)" *
398+
" are not yet supported. To request support, please open an issue at " *
399+
"https://github.com/jump-dev/MathOptInterface.jl with a reproducible " *
400+
"example.",
401+
)
402+
end
403+
404+
function _parse_section(::IO, ::Val{'L'}, ::_CacheModel)
405+
return error(
406+
"Unable to parse NL file: logical constraints ('L' sections) are not " *
407+
"yet supported. To request support, please open an issue at " *
408+
"https://github.com/jump-dev/MathOptInterface.jl with a reproducible " *
409+
"example.",
410+
)
411+
end
412+
375413
function _parse_section(io::IO, ::Val{'C'}, model::_CacheModel)
376414
index = _next(Int, io, model) + 1
377415
_read_til_newline(io)

test/FileFormats/NL/read.jl

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,83 @@ v1
515515
return
516516
end
517517

518+
function test_parse_F()
519+
model = NL._CacheModel()
520+
io = IOBuffer()
521+
write(io, "F")
522+
seekstart(io)
523+
@test_throws(
524+
ErrorException(
525+
"Unable to parse NL file: imported function descriptions ('F' " *
526+
"sections) are not yet supported. To request support, please open an " *
527+
"issue at https://github.com/jump-dev/MathOptInterface.jl with a " *
528+
"reproducible example.",
529+
),
530+
NL._parse_section(io, model),
531+
)
532+
return
533+
end
534+
535+
function test_parse_V()
536+
model = NL._CacheModel()
537+
io = IOBuffer()
538+
write(io, "V")
539+
seekstart(io)
540+
@test_throws(
541+
ErrorException(
542+
"Unable to parse NL file: defined variable definitions ('V' sections)" *
543+
" are not yet supported. To request support, please open an issue at " *
544+
"https://github.com/jump-dev/MathOptInterface.jl with a reproducible " *
545+
"example.",
546+
),
547+
NL._parse_section(io, model),
548+
)
549+
return
550+
end
551+
552+
function test_parse_L()
553+
model = NL._CacheModel()
554+
io = IOBuffer()
555+
write(io, "L")
556+
seekstart(io)
557+
@test_throws(
558+
ErrorException(
559+
"Unable to parse NL file: logical constraints ('L' sections) are not " *
560+
"yet supported. To request support, please open an issue at " *
561+
"https://github.com/jump-dev/MathOptInterface.jl with a reproducible " *
562+
"example.",
563+
),
564+
NL._parse_section(io, model),
565+
)
566+
return
567+
end
568+
569+
function test_parse_S()
570+
model = NL._CacheModel()
571+
io = IOBuffer()
572+
write(
573+
io,
574+
"""
575+
S0 8 zork
576+
02
577+
16
578+
27
579+
38
580+
49
581+
53
582+
65
583+
84
584+
""",
585+
)
586+
seekstart(io)
587+
@test_logs(
588+
(:warn, "Skipping suffix: `S0 8 zork`"),
589+
NL._parse_section(io, model),
590+
)
591+
@test eof(io)
592+
return
593+
end
594+
518595
function test_hs071()
519596
model = NL.Model()
520597
open(joinpath(@__DIR__, "data", "hs071.nl"), "r") do io

0 commit comments

Comments
 (0)