[parse] Better error message for bad packages list

When an appropriate list end is not found in the packages list, give a
more informative error message.
This commit is contained in:
Asher Mancinelli 2024-01-27 10:55:16 -08:00
parent c645514739
commit da261be209
No known key found for this signature in database
GPG key ID: 8CCDB828496E978C

View file

@ -3910,6 +3910,28 @@ fn to_packages_report<'a>(
severity: Severity::RuntimeError, severity: Severity::RuntimeError,
} }
} }
EPackages::ListEnd(pos) => {
let surroundings = Region::new(start, pos);
let region = LineColumnRegion::from_pos(lines.convert_pos(pos));
let doc = alloc.stack([
alloc.reflow(
r"I am partway through parsing a header packages list, but I got stuck here:",
),
alloc.region_with_subregion(lines.convert_region(surroundings), region),
alloc.concat([alloc.reflow("I am expecting a comma or end of list, like")]),
alloc
.parser_suggestion("packages { package_name: \"url-or-path\", }")
.indent(4),
]);
Report {
filename,
doc,
title: "WEIRD PACKAGES LIST".to_string(),
severity: Severity::RuntimeError,
}
}
EPackages::Space(error, pos) => to_space_report(alloc, lines, filename, &error, pos), EPackages::Space(error, pos) => to_space_report(alloc, lines, filename, &error, pos),