@Kosma
Вероятно, есть еще путь использовать внутренний API BAS для написания кода. Но тут на свой страх и риск, так как:
@UserTrue said in Встроенный язык:
Простой аргумент в нем нет никакого стектрейса для нахождения ошибок в блоке выполнить код, поэтому если твоя огромная простыня будет где-то крашится да и к тому же рандомно и не часто то ты заепешься логи пихать на каждой строчке, что бы понять в чем проблема.
Но это частично решаемо, если оборачивать свой код в try ... catch. Но полного stacktrace не будет, к сожалению.
try {
nonExistentFunction();
} catch (error) {
log("Error caught: " + error);
log(JSON.stringify(error));
}
Вывод ошибки:
[865451621] [06:05:57] Thread #1 : {"message":"Can't find variable: nonExistentFunction","lineNumber":3,"sourceId":2310798157248,"fileName":"","expressionBeginOffset":25,"expressionCaretOffset":44,"expressionEndOffset":44}
Скриншот:
Код:
// Retrieve file or directory information from the profiles directory path.
var json = JSON.parse(native("filesystem", "fileinfo", [[_PROFILES_DIR_NAME]]));
// Extract and store the existence status and type (file or directory) from the retrieved information.
FILEINFO_EXISTS = json["exists"];
FILEINFO_IS_DIRECTORY = json["is_directory"];
// Log the existence status and type of the profiles directory for debugging and verification purposes.
log("[gmail_tools][prepare] checking profiles dir, FILEINFO_EXISTS: " + FILEINFO_EXISTS + ", FILEINFO_IS_DIRECTORY: " + FILEINFO_IS_DIRECTORY);
// Validate the existence and type of the profiles directory.
// If it doesn't exist or isn't a directory, halt the process with an error message.
if (FILEINFO_EXISTS !== true || FILEINFO_IS_DIRECTORY !== true) {
fail_user("ProfilesPath doesn’t exist or is not a directory.", true);
}
// Retrieve and log additional configuration information.
var profiles_dir_name = VAR__PROFILES_DIR_NAME;
log("[gmail_tools][prepare] threads: " + {{Threads}} + ", profiles dir: " + profiles_dir_name);
/////// END OF CHECKING PREREQUISITES ///////
// Initiate a search for subdirectories within the profiles directory.
native_async("filesystem", "search", JSON.stringify({
folder: profiles_dir_name,
mask: "*",
contains: "",
include_folders: true,
include_files: false,
recursive: false
}))!;
// Retrieve the results of the asynchronous search.
var result = _result();
// Parse the result to extract the directory information.
profiles_sub_dirs = JSON.parse(result)["d"];
log("[gmail_tools][prepare] found profiles count: " + profiles_sub_dirs.length);
// If no profile directories are found, halt the process with an error message.
if (profiles_sub_dirs.length == 0) {
fail_user("Could not find any subdirectories in the provided directory: " + profiles_dir_name, true);
}
// Initialize an array to store the paths of valid profile directories.
var profiles_dir_checked = [];
// Iterate through each subdirectory found in the profiles directory.
profiles_sub_dirs.forEach(function (profile_dir) {
// Construct the path to the "Default" folder within each profile directory.
profile_dir_checking_file = _path.join([_avoid_nil(profile_dir), _avoid_nil("Default")]);
// Log the path being checked for easy tracking and debugging.
log("[gmail_tools][prepare] checking profile dir: " + profile_dir);
// Retrieve file or directory information of the "Default" folder.
var json = JSON.parse(native("filesystem", "fileinfo", profile_dir_checking_file));
// Extract and store the existence status from the retrieved information.
FILEINFO_EXISTS = json["exists"];
FILEINFO_IS_DIRECTORY = json["is_directory"];
// Check if the "Default" folder exists.
if (FILEINFO_EXISTS !== true) {
// If not, log a message and skip to the next iteration.
log("[gmail_tools][prepare] not a profile dir, skipping: " + profile_dir);
return;
}
// If the "Default" folder exists, add the profile directory to the list of valid profiles.
profiles_dir_checked.push(profile_dir);
});
// Log the number of valid profile directories found.
log("[gmail_tools][prepare] found valid profiles: " + profiles_dir_checked.length);
// Fill resource
RClear("PROFILE_DIR")
RSync("PROFILE_DIR")
for(var i = 0;i<(profiles_dir_checked).length;i++){
RInsert("PROFILE_DIR",(profiles_dir_checked)[i],false)
}
RSync("PROFILE_DIR")
Положительные моменты:
- пишешь кодом на Javascript
- вероятно, огромное кол-во разработчиков BAS не смогу ни понять ни изменить твои скрипты. Если будешь делать скрипты на продажу, поддерживать сможешь только ты.
Отрицательные моменты:
- если пишешь на заказ, некоторые заказчики не захотят работу в таком виде, так как не смогут в будущем поправить по мелочи, не оплачивая никому денег
- код скриптов можно скрыть, в отличии от кода на NodeJS, который будет идти в явном виде.
- при обновлении BAS, может потребоваться обновить код, если внутренний API функций изменится. Это решается ровно также, как и в обычном мире программирования - unit тестами. Да, функции в BAS тоже можно покрыть тестами. Также можно и написать функциональные тесты, что скрипт, как минимум, вообще запускается и не падает с синтаксическими ошибками. Я это же делал.
- ну и еще момент - это возможность себя почувствовать мега-хакером, который кодит не так, как все 😃