!274 完善当 JS Bundle文件超过大小限制(30K)时的用户提示

Merge pull request !274 from piggyguy_jdx/improve_file_size_tracing
This commit is contained in:
openharmony_ci
2021-07-27 14:09:28 +00:00
committed by Gitee
2 changed files with 35 additions and 14 deletions
+10 -5
View File
@@ -28,7 +28,8 @@ void PrintInfo(const char *format, va_list args)
void HILOG_FATAL(HiLogModuleType mod, const char *msg, ...)
{
printf("[FATAL]:");
(void)(mod);
printf("[ACELite][FATAL]:");
va_list args;
va_start(args, msg);
PrintInfo(msg, args);
@@ -37,7 +38,8 @@ void HILOG_FATAL(HiLogModuleType mod, const char *msg, ...)
void HILOG_ERROR(HiLogModuleType mod, const char *msg, ...)
{
printf("[ERROR]:");
(void)(mod);
printf("[ACELite][ERROR]:");
va_list args;
va_start(args, msg);
PrintInfo(msg, args);
@@ -46,7 +48,8 @@ void HILOG_ERROR(HiLogModuleType mod, const char *msg, ...)
void HILOG_INFO(HiLogModuleType mod, const char *msg, ...)
{
printf("[INFO]:");
(void)(mod);
printf("[ACELite][INFO]:");
va_list args;
va_start(args, msg);
PrintInfo(msg, args);
@@ -55,7 +58,8 @@ void HILOG_INFO(HiLogModuleType mod, const char *msg, ...)
void HILOG_WARN(HiLogModuleType mod, const char *msg, ...)
{
printf("[WARN]:");
(void)(mod);
printf("[ACELite][WARN]:");
va_list args;
va_start(args, msg);
PrintInfo(msg, args);
@@ -64,7 +68,8 @@ void HILOG_WARN(HiLogModuleType mod, const char *msg, ...)
void HILOG_DEBUG(HiLogModuleType mod, const char *msg, ...)
{
printf("[DEBUG]:");
(void)(mod);
printf("[ACELite][DEBUG]:");
va_list args;
va_start(args, msg);
PrintInfo(msg, args);
+25 -9
View File
@@ -604,6 +604,30 @@ static int32_t OpenFileInternal(const char * const orgFullPath, bool binary = fa
return open(path, O_RDONLY);
}
static void OutputFileMaxLimitationTrace(const char * const fullPath, size_t limitation)
{
if (fullPath == nullptr || strlen(fullPath) == 0) {
return;
}
const char *ptr = strrchr(fullPath, PATH_SEPARATOR);
const size_t fileNameMaxLen = 32;
if (ptr == nullptr || strlen(ptr) > fileNameMaxLen) {
HILOG_ERROR(HILOG_MODULE_ACE, "file name too long.");
return;
}
const size_t traceDataLen = 128;
char traceData[traceDataLen] = {0};
const size_t oneKB = 1024;
size_t currentLimitation = limitation / oneKB;
if (sprintf_s(traceData, traceDataLen, "%s is bigger than %d KB.\n", (ptr + 1), currentLimitation) < 0) {
HILOG_ERROR(HILOG_MODULE_ACE, "splice trace data failed.");
return;
}
LogOutLevel(LogLevel::LOG_LEVEL_ERR);
LogString(LogLevel::LOG_LEVEL_ERR, traceData);
}
/**
* Check if the file length is under MAX limitation.
*/
@@ -616,15 +640,7 @@ static bool CheckFileLength(const char * const fullPath, int32_t &outFileSize)
return false;
}
if (fileSize > FILE_CONTENT_LENGTH_MAX) {
LogString(LogLevel::LOG_LEVEL_ERR, "[JS Exception]: file ");
LogString(LogLevel::LOG_LEVEL_ERR, fullPath);
LogString(LogLevel::LOG_LEVEL_ERR, " is bigger than ");
const uint8_t len = 10;
char markdata[len];
const uint32_t num = 30; // calculate thresold by file type
if (sprintf_s(markdata, len, "%d kb.\n", num) < 0) {
HILOG_ERROR(HILOG_MODULE_ACE, "init error message failed");
}
OutputFileMaxLimitationTrace(fullPath, FILE_CONTENT_LENGTH_MAX);
ACE_ERROR_CODE_PRINT(EXCE_ACE_ROUTER_REPLACE_FAILED, EXCE_ACE_PAGE_FILE_TOO_HUGE);
return false;
}