Skip to content

Commit 70d5b0b

Browse files
Improve error handling and ignore parent and current folder reference
1 parent da50d61 commit 70d5b0b

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

api/AltV.Net.Async/AsyncModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public override void OnClientEventEvent(IPlayer player, string name, ref MValueA
209209
}
210210
catch (Exception e)
211211
{
212-
AltAsync.Log($"Execution of ${name} threw an error: {e}");
212+
AltAsync.Log($"Execution of {name} threw an error: {e}");
213213
}
214214
}
215215
else
@@ -314,7 +314,7 @@ public override void OnServerEventEvent(string name, ref MValueArray args, MValu
314314
}
315315
catch (Exception e)
316316
{
317-
AltAsync.Log($"Execution of ${name} threw an error: {e}");
317+
AltAsync.Log($"Execution of {name} threw an error: {e}");
318318
}
319319
}
320320
else

runtime/include/CoreClr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class CoreClr {
7171

7272
void GetPath(alt::IServer* server, const char* defaultPath);
7373

74+
/**
75+
* prints out error when error code in known
76+
* @param server
77+
* @param errorCode
78+
* @return true when error code is known
79+
*/
80+
bool PrintError(alt::IServer* server, int errorCode);
81+
7482
private:
7583
#ifdef _WIN32
7684
HMODULE _coreClrLib;

runtime/src/CoreClr.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,9 @@ bool CoreClr::GetDelegate(alt::IServer* server, void* runtimeHost, unsigned int
137137
}
138138
int result = _createDelegate(runtimeHost, domainId, moduleName, classPath, methodName, callback);
139139
if (result < 0) {
140-
//TODO: https://github.com/rashiph/DecompliedDotNetLibraries/blob/6056fc6ff7ae8fb3057c936d9ebf36da73f990a6/mscorlib/System/__HResults.cs
141-
if (result == -2146234304) {
142-
server->LogInfo(
143-
alt::String(
144-
"coreclr-module: Your server needs to be compiled and needs to target (<TargetFramework>netcoreappX.X</TargetFramework>) with the same .net core version that is installed on your workstation"));
140+
if (this->PrintError(server, result)) {
145141
return false;
146142
}
147-
if (result == -2147024894) {
148-
server->LogInfo(
149-
alt::String(
150-
"coreclr-module: You need to place the AltV.Net.dll in your resource directory. Use publish to generate all dlls."));
151-
return false;
152-
}
153-
server->LogInfo(alt::String(strerror(errno)));
154-
char* x_str = new char[10];
155-
sprintf(x_str, "%d", result);
156-
server->LogInfo(
157-
alt::String(x_str));
158-
delete[] x_str;
159143
server->LogInfo(
160144
alt::String("coreclr-module: Unable to get ") + moduleName + ":" + classPath + "." + methodName +
161145
" domain:" +
@@ -284,6 +268,7 @@ void CoreClr::CreateAppDomain(alt::IServer* server, alt::IResource* resource, co
284268

285269
if (result < 0) {
286270
server->LogInfo(alt::String("coreclr-module: Unable to create app domain: 0x"));
271+
this->PrintError(server, result);
287272
} else {
288273
server->LogInfo(alt::String("coreclr-module: Created app domain: 0x") + appPath);
289274
}
@@ -335,7 +320,7 @@ void CoreClr::GetPath(alt::IServer* server, const char* defaultPath) {
335320
struct dirent* entry;
336321
char* greatest = nullptr;
337322
while ((entry = readdir(directory)) != nullptr) {
338-
if (entry->d_type == DT_DIR) {
323+
if (entry->d_type == DT_DIR && memcmp(entry->d_name, ".", 1) != 0 && memcmp(entry->d_name, "..", 2) != 0) {
339324
server->LogInfo(alt::String("coreclr-module: version found: ") + entry->d_name);
340325
if (greatest == nullptr) {
341326
greatest = entry->d_name;
@@ -362,4 +347,26 @@ void CoreClr::GetPath(alt::IServer* server, const char* defaultPath) {
362347
memset(runtimeDirectory, '\0', size);
363348
strcpy(runtimeDirectory, defaultPath);
364349
strcat(runtimeDirectory, greatest);
350+
}
351+
352+
//TODO: https://github.com/rashiph/DecompliedDotNetLibraries/blob/6056fc6ff7ae8fb3057c936d9ebf36da73f990a6/mscorlib/System/__HResults.cs
353+
bool CoreClr::PrintError(alt::IServer* server, int errorCode) {
354+
if (errorCode == -2146234304) {
355+
server->LogInfo(
356+
alt::String(
357+
"coreclr-module: Your server needs to be compiled and needs to target (<TargetFramework>netcoreappX.X</TargetFramework>) with the same .net core version that is installed on your workstation"));
358+
return true;
359+
} else if (errorCode == -2147024894) {
360+
server->LogInfo(
361+
alt::String(
362+
"coreclr-module: You need to place the AltV.Net.dll in your resource directory. Use publish to generate all dlls."));
363+
return true;
364+
}
365+
server->LogInfo(alt::String(strerror(errno)));
366+
char* x_str = new char[10];
367+
sprintf(x_str, "%d", errorCode);
368+
server->LogInfo(
369+
alt::String(x_str));
370+
delete[] x_str;
371+
return false;
365372
}

0 commit comments

Comments
 (0)