Compare commits

..

2 Commits

Author SHA1 Message Date
12e5623fe6 [ox/logconn] Add exception handling for logger thread
All checks were successful
Build / build (push) Successful in 1m18s
2025-06-19 23:56:26 -05:00
cfdfb0a8c9 [studio] Fix file deletion to close file even if not active 2025-06-19 23:55:47 -05:00
2 changed files with 49 additions and 32 deletions

View File

@@ -91,23 +91,28 @@ ox::Error LoggerConn::sendInit(const InitTraceMsg &msg) noexcept {
} }
void LoggerConn::msgSend() noexcept { void LoggerConn::msgSend() noexcept {
while (true) { try {
std::unique_lock lk(m_waitMut);
m_waitCond.wait(lk);
if (!m_running) {
break;
}
std::lock_guard const buffLk(m_buffMut);
while (true) { while (true) {
Array<char, units::KB> tmp; std::unique_lock lk(m_waitMut);
const auto read = m_buff.read(tmp.data(), tmp.size()); m_waitCond.wait(lk);
if (!read) { if (!m_running) {
break; break;
} }
oxAssert(read <= tmp.size(), "logger trying to read too much data"); std::lock_guard const buffLk(m_buffMut);
//std::printf("LoggerConn: sending %lu bytes\n", read); while (true) {
std::ignore = send(tmp.data(), read); Array<char, units::KB> tmp;
const auto read = m_buff.read(tmp.data(), tmp.size());
if (!read) {
break;
}
oxAssert(read <= tmp.size(), "logger trying to read too much data");
//std::printf("LoggerConn: sending %lu bytes\n", read);
std::ignore = send(tmp.data(), read);
}
} }
} catch (std::exception const &e) {
oxErrf("Exception in logger thread: {}\n", e.what());
oxAssert(false, "logger thread exception");
} }
} }

View File

@@ -551,24 +551,36 @@ ox::Error StudioUI::handleMoveFile(ox::StringViewCR oldPath, ox::StringViewCR ne
ox::Error StudioUI::handleDeleteDir(ox::StringViewCR path) noexcept { ox::Error StudioUI::handleDeleteDir(ox::StringViewCR path) noexcept {
auto const p = sfmt("{}/", path); auto const p = sfmt("{}/", path);
for (auto &e : m_editors) { std::ignore = m_editors.erase(
if (beginsWith(e->itemPath(), p)) { std::remove_if(
oxLogError(closeFile(path)); m_editors.begin(), m_editors.end(),
m_closeActiveTab = true; [&](ox::UPtr<BaseEditor> const &e) {
break; if (beginsWith(e->itemPath(), p)) {
} oxLogError(closeFile(path));
} if (e.get() != m_activeEditor) {
return true;
}
m_closeActiveTab = true;
}
return false;
}));
return m_projectExplorer.refreshProjectTreeModel(); return m_projectExplorer.refreshProjectTreeModel();
} }
ox::Error StudioUI::handleDeleteFile(ox::StringViewCR path) noexcept { ox::Error StudioUI::handleDeleteFile(ox::StringViewCR path) noexcept {
for (auto &e : m_editors) { std::ignore = m_editors.erase(
if (path == e->itemPath()) { std::remove_if(
oxLogError(closeFile(path)); m_editors.begin(), m_editors.end(),
m_closeActiveTab = true; [&](ox::UPtr<BaseEditor> const &e) {
break; if (path == e->itemPath()) {
} oxLogError(closeFile(path));
} if (e.get() != m_activeEditor) {
return true;
}
m_closeActiveTab = true;
}
return false;
}));
return m_projectExplorer.refreshProjectTreeModel(); return m_projectExplorer.refreshProjectTreeModel();
} }
@@ -666,10 +678,10 @@ ox::Error StudioUI::openFileActiveTab(ox::StringViewCR path, bool const makeActi
} }
OX_REQUIRE(ext, fileExt(path)); OX_REQUIRE(ext, fileExt(path));
// create Editor // create Editor
BaseEditor *editor = nullptr; ox::UPtr<BaseEditor> editor;
auto const err = m_editorMakers.contains(ext) ? auto const err = m_editorMakers.contains(ext) ?
m_editorMakers[ext](path).moveTo(editor) : m_editorMakers[ext](path).to<ox::UPtr<BaseEditor>>().moveTo(editor) :
ox::makeCatch<ClawEditor>(m_sctx, path).moveTo(editor); ox::make_unique_catch<ClawEditor>(m_sctx, path).moveTo(editor);
if (err) { if (err) {
if constexpr(!ox::defines::Debug) { if constexpr(!ox::defines::Debug) {
oxErrf("Could not open Editor: {}\n", toStr(err)); oxErrf("Could not open Editor: {}\n", toStr(err));
@@ -679,11 +691,11 @@ ox::Error StudioUI::openFileActiveTab(ox::StringViewCR path, bool const makeActi
return err; return err;
} }
editor->closed.connect(this, &StudioUI::closeFile); editor->closed.connect(this, &StudioUI::closeFile);
m_editors.emplace_back(editor); auto const &e = m_editors.emplace_back(std::move(editor));
m_openFiles.emplace_back(path); m_openFiles.emplace_back(path);
if (makeActiveTab) { if (makeActiveTab) {
m_activeEditor = m_editors.back().value->get(); m_activeEditor = m_editors.back().value->get();
m_activeEditorUpdatePending = editor; m_activeEditorUpdatePending = e.get();
} }
// save to config // save to config
studio::editConfig<StudioConfig>(keelCtx(m_tctx), [&path](StudioConfig &config) { studio::editConfig<StudioConfig>(keelCtx(m_tctx), [&path](StudioConfig &config) {