Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src-client/lse/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "legacy/engine/EngineManager.h"
#include "legacy/engine/EngineOwnData.h"
#include "legacy/utils/ScriptErrorPrinter.h"
#include "ll/api/io/FileUtils.h" // IWYU pragma: keep
#include "ll/api/mod/Mod.h"
#include "ll/api/mod/ModManager.h"
Expand Down Expand Up @@ -242,6 +243,7 @@ ll::Expected<> PluginManager::enableScriptPlugin(std::string_view name, bool isH
if (scriptEngine) {
auto error = [&] {
EngineScope engineScope(scriptEngine.get());
::legacy::script_error::printException(e, LegacyScriptEngine::getLogger());
return ll::makeStringError(
"Failed to enable plugin {0}: {1}\n{2}"_tr(manifest.name, e.message(), e.stacktrace())
);
Expand Down
2 changes: 2 additions & 0 deletions src-server/lse/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "legacy/engine/EngineManager.h"
#include "legacy/engine/EngineOwnData.h"
#include "legacy/utils/ScriptErrorPrinter.h"
#include "ll/api/io/FileUtils.h" // IWYU pragma: keep
#include "ll/api/mod/Mod.h"
#include "ll/api/mod/ModManager.h"
Expand Down Expand Up @@ -219,6 +220,7 @@ ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) {
if (scriptEngine) {
auto error = [&] {
EngineScope engineScope(scriptEngine.get());
::legacy::script_error::printException(e, LegacyScriptEngine::getLogger());
return ll::makeStringError(
"Failed to load plugin {0}: {1}\n{2}"_tr(manifest.name, e.message(), e.stacktrace())
);
Expand Down
13 changes: 8 additions & 5 deletions src/legacy/api/APIHelp.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#pragma once

#include "legacy/engine/EngineOwnData.h"
#include "legacy/utils/ScriptErrorPrinter.h"
#include "legacy/utils/JsonHelper.h"
#include "legacy/utils/UsingScriptX.h"
#include "ll/api/utils/ErrorUtils.h"
Expand Down Expand Up @@ -69,17 +70,19 @@ inline Exception WrongArgsCountException(std::string const& func) {

#define CATCH \
catch (...) { \
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger()); \
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger()); \
LogErrorWithInfo(__FUNCTION__); \
}

#define CATCH_WITH_MESSAGE(...) \
#define CATCH_WITH_API_AND_MESSAGE(API_NAME, ...) \
catch (...) { \
lse::LegacyScriptEngine::getLogger().error(__VA_ARGS__); \
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger()); \
LogErrorWithInfo(__FUNCTION__); \
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger()); \
LogErrorWithInfo(API_NAME); \
}

#define CATCH_WITH_MESSAGE(...) CATCH_WITH_API_AND_MESSAGE(__FUNCTION__, __VA_ARGS__)

// 截获回调函数异常
#define CATCH_IN_CALLBACK(...) CATCH_WITH_MESSAGE("In callback for", __VA_ARGS__)

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ void InitBasicEventListeners() {
}
} catch (...) {
lse::LegacyScriptEngine::getLogger().error("Error occurred in Engine Message Loop!");
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/legacy/api/EventAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void CallEventImpl(EventListener& listener, bool& returnValue, EVENT_TYPES type,
returnValue = false;
}
}
CATCH_WITH_MESSAGE("CallEvent Callback Failed! In Event: {}", EventTypeToString(type))
CATCH_WITH_API_AND_MESSAGE("listen", "CallEvent Callback Failed! In Event: {}", EventTypeToString(type))
}

#define FakeCallEvent(ENGINE, TYPE, ...) \
Expand All @@ -195,7 +195,7 @@ void FakeCallEventImpl(EventListener& listener, ScriptEngine* engine, EVENT_TYPE
try {
listener.func.get().call({}, args...);
}
CATCH_WITH_MESSAGE("FakeCallEvent Callback Failed!")
CATCH_WITH_API_AND_MESSAGE("listen", "FakeCallEvent Callback Failed!")
}
}

Expand All @@ -206,6 +206,6 @@ void FakeCallEventImpl(EventListener& listener, ScriptEngine* engine, EVENT_TYPE
#define IF_LISTENED_END(TYPE) \
catch (...) { \
lse::LegacyScriptEngine::getLogger().error("Event Callback Failed! In Event: {}", EventTypeToString(TYPE)); \
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger()); \
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger()); \
} \
}
2 changes: 1 addition & 1 deletion src/legacy/api/LegacyCommandAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void registerLegacyCommands() {
registerLegacyCommand(name, data.description, data.level, data.engine, data.playerFunc, data.consoleFunc);
} catch (...) {
LegacyScriptEngine::getLogger().error("Failed to register legacy command: {}"_tr(name));
ll::error_utils::printCurrentException(LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(LegacyScriptEngine::getLogger());
}
}
localShareData->fakeCommandsMap.clear();
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/api/NetworkAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace ll::coro;
catch (...) { \
EngineScope enterCoro(engine); \
lse::LegacyScriptEngine::getLogger().error(LOG); \
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger()); \
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger()); \
LogErrorWithInfo(__FUNCTION__); \
co_return; \
}
Expand Down Expand Up @@ -345,7 +345,7 @@ Local<Value> WSClientClass::connectAsync(Arguments const& args) {
"WSClientClass::connectAsync Failed! In plugin: {}",
pluginName
);
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
}).detach();
return Boolean::newBoolean(true);
Expand Down Expand Up @@ -761,7 +761,7 @@ Local<Value> HttpServerClass::listen(Arguments const& args) const {
svr->listen(addr, port);
} catch (...) {
lse::LegacyScriptEngine::getLogger().error("Failed to listen {}:{}", addr, port);
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
}).detach();
return this->getScriptObject(); // return self
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/api/SystemAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool NewProcess(
if (callback) callback(static_cast<int>(exitCode), std::move(strOutput));
} catch (...) {
lse::LegacyScriptEngine::getLogger().error("NewProcess Callback Failed!");
ll::utils::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
}).detach();

Expand Down
26 changes: 13 additions & 13 deletions src/legacy/engine/MessageSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ ModuleMessageResult ModuleMessage::broadcastLocal(MessageType type, string const
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printException(e, lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printException(e, lse::LegacyScriptEngine::getLogger());
} catch (...) {
EngineScope scope(engine.get());
lse::LegacyScriptEngine::getLogger().error(
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
}
return ModuleMessageResult(msgId, engineList);
Expand All @@ -145,14 +145,14 @@ ModuleMessageResult ModuleMessage::broadcastGlobal(MessageType type, string cons
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printException(e, lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printException(e, lse::LegacyScriptEngine::getLogger());
} catch (...) {
EngineScope scope(engine.get());
lse::LegacyScriptEngine::getLogger().error(
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
}
return ModuleMessageResult(msgId, engineList);
Expand All @@ -178,14 +178,14 @@ ModuleMessage::broadcastTo(std::string const& toModuleType, MessageType type, st
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printException(e, lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printException(e, lse::LegacyScriptEngine::getLogger());
} catch (...) {
EngineScope scope(engine.get());
lse::LegacyScriptEngine::getLogger().error(
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
}
}
Expand All @@ -209,14 +209,14 @@ ModuleMessage::sendTo(std::shared_ptr<ScriptEngine> engine, MessageType type, st
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printException(e, lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printException(e, lse::LegacyScriptEngine::getLogger());
} catch (...) {
EngineScope scope(engine.get());
lse::LegacyScriptEngine::getLogger().error(
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
return ModuleMessageResult(msgId, {});
}
Expand All @@ -240,14 +240,14 @@ ModuleMessage::sendToRandom(std::string const& toModuleType, MessageType type, s
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printException(e, lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printException(e, lse::LegacyScriptEngine::getLogger());
} catch (...) {
EngineScope scope(engine.get());
lse::LegacyScriptEngine::getLogger().error(
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
}
}
Expand All @@ -270,7 +270,7 @@ bool ModuleMessage::sendResult(MessageType typ, std::string const& dat, int64_t
"Fail to post message to plugin {}",
getEngineData(engine)->pluginName
);
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
return false;
}
Expand Down Expand Up @@ -338,10 +338,10 @@ void MessageSystemLoopOnce() {
"Error occurred in Engine Message Loop! In plugin: {}",
getEngineOwnData()->pluginName
);
ll::error_utils::printException(e, lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printException(e, lse::LegacyScriptEngine::getLogger());
} catch (...) {
lse::LegacyScriptEngine::getLogger().error("Error occurred in Engine Message Loop!");
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/engine/RemoteCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void RemoteSyncCallRequest(ModuleMessage& msg) {
if (engine) {
EngineScope enter(engine);
lse::LegacyScriptEngine::getLogger().error("In plugin: {}", getEngineOwnData()->pluginName);
ll::error_utils::printException(e, lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printException(e, lse::LegacyScriptEngine::getLogger());
}

// Feedback
Expand All @@ -73,7 +73,7 @@ void RemoteSyncCallRequest(ModuleMessage& msg) {
}
} catch (...) {
lse::LegacyScriptEngine::getLogger().error("Error occurred in remote engine!");
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());

// Feedback
if (!msg.sendResult(ModuleMessage::MessageType::RemoteSyncCallReturn, "[null]")) {
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/engine/TimeTaskSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ std::unordered_map<uint64, ScriptEngine*> timeTaskMap;
EngineScope scope(data.engine); \
lse::LegacyScriptEngine::getLogger() \
.error("Error occurred in {}, in plugin: {}", TASK_TYPE, getEngineData(data.engine)->pluginName); \
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger()); \
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger()); \
}

int NewTimeout(const Local<Function>& func, const std::vector<Local<Value>>& paras, int timeout) {
Expand Down Expand Up @@ -199,7 +199,7 @@ bool ClearTimeTask(unsigned int const& id) {
}
} catch (...) {
lse::LegacyScriptEngine::getLogger().error("Fail in ClearTimeTask");
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
return true;
}
Expand All @@ -218,6 +218,6 @@ void LLSERemoveTimeTaskData(std::shared_ptr<ScriptEngine> const& engine) {
}
} catch (...) {
lse::LegacyScriptEngine::getLogger().info("Fail in LLSERemoveTimeTaskData");
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
}
4 changes: 2 additions & 2 deletions src/legacy/main/BuiltinCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool ProcessDebugEngine(std::string const& cmd) {
logger.info(sout.str());
PrintDebugSign();
} catch (...) {
ll::error_utils::printCurrentException(logger);
::legacy::script_error::printCurrentException(logger);
PrintDebugSign();
}
return false;
Expand Down Expand Up @@ -72,7 +72,7 @@ void RegisterDebugCommand() {
PrintValue(sout, result);
output.success(sout.str());
} catch (...) {
ll::error_utils::printCurrentException(logger);
::legacy::script_error::printCurrentException(logger);
}
} else {
if (InConsoleDebugMode) {
Expand Down
10 changes: 7 additions & 3 deletions src/legacy/main/NodeJsHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "fmt/format.h"
#include "legacy/engine/EngineOwnData.h"
#include "legacy/utils/ScriptErrorPrinter.h"
#include "legacy/utils/Utils.h"
#include "ll/api/Expected.h"
#include "ll/api/base/Containers.h"
Expand Down Expand Up @@ -175,6 +176,7 @@ std::shared_ptr<ScriptEngine> newEngine() {
}
v8::Isolate* isolate = setup->isolate();
node::Environment* env = setup->env();
isolate->SetCaptureStackTraceForUncaughtExceptions(true);

v8::Locker locker(isolate);
v8::Isolate::Scope isolate_scope(isolate);
Expand Down Expand Up @@ -325,7 +327,9 @@ bool loadPluginCode(
}
if (errorMsg->IsString()) {
v8::String::Utf8Value value{it->second->isolate(), errorMsg};
logger.error(std::string_view{*value, static_cast<size_t>(value.length())});
auto error = std::string{*value, static_cast<size_t>(value.length())};
::legacy::script_error::printRawError(error, logger);
logger.error(error);
loadFailed = true;
}
}
Expand Down Expand Up @@ -397,7 +401,7 @@ bool stopEngine(node::Environment* env) {
return true;
} catch (...) {
lse::LegacyScriptEngine::getLogger().error("Fail to stop engine {}", static_cast<void*>(env));
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
return false;
}
}
Expand Down Expand Up @@ -597,7 +601,7 @@ int executeNpmCommand(std::vector<std::string> npmArgs, std::string workingDir)
exit_code = node::SpinEventLoop(env).FromMaybe(exit_code);
} catch (...) {
lse::LegacyScriptEngine::getLogger().error("Fail to execute NPM command. Error occurs");
ll::error_utils::printCurrentException(lse::LegacyScriptEngine::getLogger());
::legacy::script_error::printCurrentException(lse::LegacyScriptEngine::getLogger());
}
node::Stop(env);
}
Expand Down
3 changes: 2 additions & 1 deletion src/legacy/main/PythonHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "legacy/api/CommandAPI.h"
#include "legacy/engine/EngineManager.h"
#include "legacy/engine/TimeTaskSystem.h"
#include "legacy/utils/ScriptErrorPrinter.h"
#include "legacy/utils/Utils.h"
#include "ll/api/utils/StringUtils.h"
#include "lse/Entry.h"
Expand Down Expand Up @@ -213,7 +214,7 @@ bool processPythonDebugEngine(std::string const& cmd) {
} catch (...) {
isInsideCodeBlock = false;
codeBuffer.clear();
ll::error_utils::printCurrentException(logger);
::legacy::script_error::printCurrentException(logger);
}
}
PrintPyDebugSign();
Expand Down
Loading