1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-24 06:15:07 +00:00

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

View file

@ -39,11 +39,14 @@ const GUI::TextDocument& ProjectFile::document() const
{ {
if (!m_document) { if (!m_document) {
m_document = CodeDocument::create(LexicalPath(m_name)); m_document = CodeDocument::create(LexicalPath(m_name));
auto file = Core::File::construct(m_name); auto file_or_error = Core::File::open(m_name, Core::File::ReadOnly);
if (!file->open(Core::File::ReadOnly)) { if (file_or_error.is_error()) {
ASSERT_NOT_REACHED(); 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; return *m_document;
} }