HackStudio: Don't assert when project has non-existent file

If a project contains "foo.cpp" but we can't open "foo.cpp", just go
with an empty text document for now, and we'll create "foo.cpp" when
the user saves.
This commit is contained in:
Andreas Kling 2020-10-25 13:41:31 +01:00
parent 387607503c
commit 47a3d81731
Notes: sideshowbarker 2024-07-19 01:44:30 +09:00

View file

@ -39,11 +39,14 @@ const GUI::TextDocument& ProjectFile::document() const
{
if (!m_document) {
m_document = CodeDocument::create(LexicalPath(m_name));
auto file = Core::File::construct(m_name);
if (!file->open(Core::File::ReadOnly)) {
ASSERT_NOT_REACHED();
auto file_or_error = Core::File::open(m_name, Core::File::ReadOnly);
if (file_or_error.is_error()) {
warnln("Couldn't open '{}': {}", m_name, file_or_error.error());
// This is okay though, we'll just go with an empty document and create the file when saving.
} else {
auto& file = *file_or_error.value();
m_document->set_text(file.read_all());
}
m_document->set_text(file->read_all());
}
return *m_document;
}