Skip to content

Commit a264144

Browse files
committed
Show error to user when a file fails to open
1 parent e735279 commit a264144

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

editor/src/document/document_file.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub use super::layer_panel::*;
22
use crate::{frontend::layer_panel::*, EditorError};
33
use glam::{DAffine2, DVec2};
4-
use graphene::{document::Document as InternalDocument, LayerId};
4+
use graphene::{document::Document as InternalDocument, DocumentError, LayerId};
55
use serde::{Deserialize, Serialize};
66
use std::collections::HashMap;
77

@@ -201,7 +201,8 @@ impl DocumentMessageHandler {
201201
doc.document = handle;
202202
Ok(doc)
203203
}
204-
Err(_) => Err(EditorError::Document(String::from("Failed to parse file content"))),
204+
Err(DocumentError::InvalidFile(msg)) => Err(EditorError::Document(msg)),
205+
_ => Err(EditorError::Document(String::from("Failed to open file"))),
205206
}
206207
}
207208

editor/src/document/document_message_handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
191191
}
192192
OpenDocument(name, serialized_contents) => {
193193
let res = DocumentMessageHandler::with_name_content(name, serialized_contents);
194-
if res.is_err() {
195-
// how can we show an error message in the UI?
196-
return;
194+
match res {
195+
Ok(doc) => {
196+
self.load_document(doc, responses);
197+
}
198+
Err(e) => responses.push_back(FrontendMessage::DisplayError { description: e.to_string() }.into()),
197199
}
198-
let doc = res.unwrap();
199-
self.load_document(doc, responses);
200200
}
201201
GetOpenDocumentsList => {
202202
// Send the list of document tab names

graphene/src/document.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn split_path(path: &[LayerId]) -> Result<(&[LayerId], LayerId), DocumentError>
3434

3535
impl Document {
3636
pub fn with_content(serialized_content: &String) -> Result<Self, DocumentError> {
37-
serde_json::from_str(serialized_content).map_err(|_| DocumentError::InvalidFile)
37+
serde_json::from_str(serialized_content).map_err(|e| DocumentError::InvalidFile(e.to_string()))
3838
}
3939

4040
/// Wrapper around render, that returns the whole document as a Response.

graphene/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ pub use response::DocumentResponse;
1111

1212
pub type LayerId = u64;
1313

14-
#[derive(Debug, Clone, Copy, PartialEq)]
14+
#[derive(Debug, Clone, PartialEq)]
1515
pub enum DocumentError {
1616
LayerNotFound,
1717
InvalidPath,
1818
IndexOutOfBounds,
1919
NotAFolder,
2020
NonReorderableSelection,
2121
NotAShape,
22-
InvalidFile,
22+
InvalidFile(String),
2323
}

0 commit comments

Comments
 (0)