Open: a DWG file says what it is and what to do instead (#9328) (#9487)

Opening a DWG stopped with "design file is not UTF-8 JSON". It is told
apart by its signature, whatever the file is called, and the error points
to STEP or DXF.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DuBearte
2026-10-30 15:18:40 +00:00
committed by GitHub
parent ad1652683b
commit f0a5fc5016
+8
View File
@@ -825,6 +825,12 @@ pub fn read_design(bytes: &[u8]) -> Result<Document> {
if is_design_container(bytes) {
return design::read(bytes);
}
// Every DWG starts with its version (`AC1032`), whatever the file is called (#9328).
if bytes.starts_with(b"AC1") {
return Err(IoError::Invalid(
"this is a DWG file, which SolidCraft can't read: export the model as STEP and open that, or the drawing as DXF and use Insert DXF in a sketch".into(),
));
}
let s = std::str::from_utf8(bytes).map_err(|_| IoError::Invalid("design file is not UTF-8 JSON".into()))?;
// Only a file that isn't a design pays for asking whether it is a drawing.
Document::from_json(s).map_err(|e| match file_kind(bytes) {
@@ -1110,6 +1116,8 @@ mod tests {
let back = read_design(&write_design(&doc)).unwrap();
assert_eq!(back, doc);
assert!(read_design(b"\xff\xfe").is_err());
let dwg = read_design(b"AC1032\0\0\0\0\0\xff\xfe").unwrap_err().to_string();
assert!(dwg.contains("this is a DWG file") && dwg.contains("STEP") && dwg.contains("DXF"), "{dwg}");
assert!(matches!(export(&m.state(), &["nope".into()], Format::Step, "t"), Err(IoError::Empty)));
assert_eq!(Format::from_name("a.STP").unwrap(), Format::Step);
assert!(is_step_path("/x/Part.STEP") && is_step_path("a.stp") && !is_step_path("a.step.json") && !is_step_path("step"));