Skip to content

Commit c1d9ea1

Browse files
authored
Clean up some error message handling in the roundtrip tests (#1552)
* Remove an error message case that's no longer needed Looks like spec tests were updated in the meantime. * Align an error message between wasmparser and the spec interpreter Helps remove a special case for error messages. * Remove some special-cases with error messages These issues have been fixed in the upstream proposals. * Remove some more special-cased error messages No longer needed.
1 parent 790f872 commit c1d9ea1

2 files changed

Lines changed: 10 additions & 46 deletions

File tree

crates/wasmparser/src/binary_reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ impl<'a> BinaryReader<'a> {
705705
}
706706
let bytes = self.read_bytes(len)?;
707707
str::from_utf8(bytes).map_err(|_| {
708-
BinaryReaderError::new("invalid UTF-8 encoding", self.original_position() - 1)
708+
BinaryReaderError::new("malformed UTF-8 encoding", self.original_position() - 1)
709709
})
710710
}
711711

tests/roundtrip.rs

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -667,18 +667,10 @@ fn error_matches(error: &str, message: &str) -> bool {
667667
return error.contains("unexpected end-of-file");
668668
}
669669

670-
if message == "malformed UTF-8 encoding" {
671-
return error.contains("invalid UTF-8 encoding");
672-
}
673-
674670
if message == "duplicate identifier" {
675671
return error.contains("duplicate") && error.contains("identifier");
676672
}
677673

678-
if message == "unknown memory" {
679-
return error.contains("no linear memories are present");
680-
}
681-
682674
// wasmparser differentiates these cases, the spec interpreter apparently
683675
// doesn't
684676
if message == "function and code section have inconsistent lengths" {
@@ -715,9 +707,7 @@ fn error_matches(error: &str, message: &str) -> bool {
715707
// the spec interpreter will read past section boundaries when
716708
// decoding, wasmparser won't, producing different errors.
717709
|| error.contains("unexpected end-of-file")
718-
|| error.contains("malformed section id")
719-
// FIXME(WebAssembly/memory64#45)
720-
|| error.contains("trailing bytes at end of section");
710+
|| error.contains("malformed section id");
721711
}
722712

723713
if message == "integer too large" {
@@ -732,21 +722,14 @@ fn error_matches(error: &str, message: &str) -> bool {
732722
// were inflated to a larger size while not updating the binary
733723
// encoding of the size of the section.
734724
|| error.contains("invalid var_u32: integer representation too long")
735-
|| error.contains("malformed section id")
736-
// FIXME(WebAssembly/memory64#45)
737-
|| error.contains("trailing bytes at end of section")
738-
// It's tests... again... waiting for memory64 to get merged.
739-
|| error.contains("memory64 must be enabled for 64-bit tables");
725+
|| error.contains("malformed section id");
740726
}
741727

742728
// wasmparser blames a truncated file here, the spec interpreter blames the
743729
// section counts/lengths.
744730
if message == "length out of bounds" || message == "unexpected end of section or function" {
745731
return error.contains("unexpected end-of-file")
746-
|| error.contains("control frames remain at end of function")
747-
// This is the same case as "unexpected end" (below) but in
748-
// function-references fsr it includes "of section or function"
749-
|| error.contains("type index out of bounds");
732+
|| error.contains("control frames remain at end of function");
750733
}
751734

752735
// binary.wast includes a test in which a 0b (End) is eaten by a botched
@@ -769,34 +752,19 @@ fn error_matches(error: &str, message: &str) -> bool {
769752
|| error.contains("unexpected end-of-file");
770753
}
771754

772-
if message == "zero flag expected" {
773-
return error.contains("zero byte expected")
774-
// wasmparser defers some of these errors to validation
775-
|| error.contains("trailing bytes at end of section");
776-
}
777-
778-
if message == "junk after last section" {
779-
return error.contains("section out of order");
780-
}
781-
782755
// Our error for these tests is happening as a parser error of
783756
// the text file, not a validation error of the binary.
784757
if message == "memory size must be at most 65536 pages (4GiB)" {
785758
return error.contains("invalid u32 number: constant out of range");
786759
}
787760

788761
if message == "illegal opcode" {
789-
// The test suite includes "bad opcodes" that later became valid opcodes
790-
// (0xd4, function references proposal). However, they are still not
791-
// constant expressions, so we can sidestep by checking for that error
792-
// instead
793-
return error.contains("constant expression required")
794-
// The test suite contains a test with a global section where the
795-
// init expression is truncated and doesn't have an "end"
796-
// instruction. That's reported with wasmparser as end-of-file
797-
// because the end of the section was reached while the spec
798-
// interpreter says "illegal opcode".
799-
|| error.contains("unexpected end-of-file");
762+
// The test suite contains a test with a global section where the
763+
// init expression is truncated and doesn't have an "end"
764+
// instruction. That's reported with wasmparser as end-of-file
765+
// because the end of the section was reached while the spec
766+
// interpreter says "illegal opcode".
767+
return error.contains("unexpected end-of-file");
800768
}
801769
if message == "unknown global" {
802770
return error.contains("global.get of locally defined global");
@@ -806,10 +774,6 @@ fn error_matches(error: &str, message: &str) -> bool {
806774
return error.contains("global is immutable");
807775
}
808776

809-
if message == "sub type" {
810-
return error.contains("subtype");
811-
}
812-
813777
if message.starts_with("unknown operator") {
814778
return error.starts_with("unknown operator") || error.starts_with("unexpected token");
815779
}

0 commit comments

Comments
 (0)