diff --git a/playlet-lib/src/components/JobSystem/JobQueue.bs b/playlet-lib/src/components/JobSystem/JobQueue.bs index 055d5a90..365b9fcd 100644 --- a/playlet-lib/src/components/JobSystem/JobQueue.bs +++ b/playlet-lib/src/components/JobSystem/JobQueue.bs @@ -43,7 +43,7 @@ function OnRequest(event as object) as void m.pendingRequestEvents = [] end if m.pendingRequestEvents.push(event) - LogWarn("JobQueue: Job queue task is not ready, request will be queued") + LogWarnNoTelemetry("JobQueue: Job queue task is not ready, request will be queued") return end if diff --git a/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTestingJob.bs b/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTestingJob.bs index ac6d35a8..f873694d 100644 --- a/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTestingJob.bs +++ b/playlet-lib/src/components/Screens/SettingsScreen/InvidiousInstance/InvidiousInstanceTesting/InvidiousInstanceTestingJob.bs @@ -62,9 +62,7 @@ function RunTests(instance as string, content as object, cancellation as object) testNode.title = `${testNode.title} (${testNode.duration}ms)` if testNode.state = "failed" - m.noTelemetry = true - LogError(testNode.details) - m.noTelemetry = false + LogErrorNoTelemetry(testNode.details) end if if CancellationUtils.IsCancelled(cancellation) diff --git a/playlet-lib/src/components/Services/Dash/DashManifest.bs b/playlet-lib/src/components/Services/Dash/DashManifest.bs index 4a64869f..b886bf48 100644 --- a/playlet-lib/src/components/Services/Dash/DashManifest.bs +++ b/playlet-lib/src/components/Services/Dash/DashManifest.bs @@ -48,9 +48,7 @@ class DashManifest audioStreams = m.getAudioStreams(adaptiveFormats) videoStreams = m.getVideoStreams(adaptiveFormats, qualityFilter) if videoStreams.Count() = 0 - m.noTelemetry = true - LogWarn("No video streams found using quality filter:", qualityFilter, "Falling back to all video streams") - m.noTelemetry = false + LogWarnNoTelemetry("No video streams found using quality filter:", qualityFilter, "Falling back to all video streams") videoStreams = m.getVideoStreams(adaptiveFormats, {}) end if @@ -204,9 +202,7 @@ class DashManifest templateUrl = storyboard.templateUrl if templateUrl.Instr("$M") = -1 - m.noTelemetry = true - LogInfo("Invalid storyboard url: url does not contain $M:", templateUrl) - m.noTelemetry = false + LogWarnNoTelemetry("Invalid storyboard url: url does not contain $M:", templateUrl) continue for end if diff --git a/playlet-lib/src/components/Services/Innertube/NodesParser.bs b/playlet-lib/src/components/Services/Innertube/NodesParser.bs index 5c844905..d724222c 100644 --- a/playlet-lib/src/components/Services/Innertube/NodesParser.bs +++ b/playlet-lib/src/components/Services/Innertube/NodesParser.bs @@ -610,13 +610,11 @@ namespace Innertube videoId = ObjectUtils.Dig(nodeData, ["updatedMetadataEndpoint", "updatedMetadataEndpoint", "videoId"]) if not IsString(videoId) ' TODO:P1 confirm that videoPrimaryInfoRenderer has the requested video - m.noTelemetry = true #if DEBUG - LogWarn("Invalid video ID in videoPrimaryInfoRenderer", `\n`, FormatJson(nodeData)) + LogWarnNoTelemetry("Invalid video ID in videoPrimaryInfoRenderer", `\n`, FormatJson(nodeData)) #else - LogWarn("Invalid video ID in videoPrimaryInfoRenderer") + LogWarnNoTelemetry("Invalid video ID in videoPrimaryInfoRenderer") #end if - m.noTelemetry = false return invalid end if end if @@ -1735,9 +1733,7 @@ namespace Innertube function Warning(message as string, nodeData as object) as void nodeDataString = FormatJson(nodeData) - m.noTelemetry = true - LogWarn(message + `\n` + nodeDataString) - m.noTelemetry = false + LogWarnNoTelemetry(message + `\n` + nodeDataString) m.global.telemetry.LogEvent = { level: "error" diff --git a/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs b/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs index 108ea219..230fc03f 100644 --- a/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs +++ b/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs @@ -374,7 +374,11 @@ namespace Innertube request.NoCache() response = request.Await() if not response.IsSuccess() - LogError(response.ErrorMessage()) + if response.IsCancelled() + LogErrorNoTelemetry(response.ErrorMessage()) + else + LogError(response.ErrorMessage()) + end if return invalid end if @@ -409,7 +413,11 @@ namespace Innertube response = request.Await() if not response.IsSuccess() - LogError(response.ErrorMessage()) + if response.IsCancelled() + LogErrorNoTelemetry(response.ErrorMessage()) + else + LogError(response.ErrorMessage()) + end if code = "" if response.StatusCode() = 400 json = response.Json() diff --git a/playlet-lib/src/components/Services/LoungeService/LongPoller.bs b/playlet-lib/src/components/Services/LoungeService/LongPoller.bs index a654273f..97b878c8 100644 --- a/playlet-lib/src/components/Services/LoungeService/LongPoller.bs +++ b/playlet-lib/src/components/Services/LoungeService/LongPoller.bs @@ -83,9 +83,7 @@ class LongPoller ' Not receiving data for LONG_POLL_TIMEOUT_MS seconds might be a sign of a dead connection if m.socket_timer.TotalMilliseconds() > LONG_POLL_TIMEOUT_MS - m.noTelemetry = true - LogWarn("Timeout after", LONG_POLL_TIMEOUT_MS, "ms") - m.noTelemetry = false + LogWarnNoTelemetry("Timeout after", LONG_POLL_TIMEOUT_MS, "ms") m.CloseSocket() return false end if diff --git a/playlet-lib/src/components/Services/LoungeService/LoungeApi.bs b/playlet-lib/src/components/Services/LoungeService/LoungeApi.bs index cb3ceea0..6be7a696 100644 --- a/playlet-lib/src/components/Services/LoungeService/LoungeApi.bs +++ b/playlet-lib/src/components/Services/LoungeService/LoungeApi.bs @@ -555,7 +555,11 @@ class LoungeApi }) if not response.IsSuccess() - LogError(response.ErrorMessage()) + if response.StatusCode() = 400 and response.ErrorMessage().InStr("Unknown SID") <> -1 + LogErrorNoTelemetry(response.ErrorMessage()) + else + LogError(response.ErrorMessage()) + end if end if m.outgoingMessagesRequests.Delete(key) diff --git a/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockService.bs b/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockService.bs index 27e86fba..9ad255ac 100644 --- a/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockService.bs +++ b/playlet-lib/src/components/Services/SponsorBlock/SponsorBlockService.bs @@ -87,7 +87,11 @@ namespace SponsorBlock url = `${m.sponsorBlockConfig.serverAddress}${SponsorBlock.SKIP_SEGMENT_ENDPOINT}/${hashPrefix}?categories=${categoriesJson}&actionTypes=${actionTypesJson}` response = HttpClient.Get(url).Cancellation(cancellation).Await() if not response.IsSuccess() - LogError("GetSkipSegmentsForVideo failed:", response.ErrorMessage()) + if response.IsCancelled() + LogErrorNoTelemetry(response.ErrorMessage()) + else + LogError(response.ErrorMessage()) + end if return invalid end if diff --git a/playlet-lib/src/components/Telemetry/Sentry.bs b/playlet-lib/src/components/Telemetry/Sentry.bs index f567d0d7..c4cec5f9 100644 --- a/playlet-lib/src/components/Telemetry/Sentry.bs +++ b/playlet-lib/src/components/Telemetry/Sentry.bs @@ -78,9 +78,7 @@ namespace Sentry response = request.Await() if not response.IsSuccess() #if DEBUG - m.noTelemetry = true - LogError("Failed to send event to Sentry:", response.ErrorMessage()) - m.noTelemetry = false + LogErrorNoTelemetry("Failed to send event to Sentry:", response.ErrorMessage()) #end if statusCode = response.StatusCode() diff --git a/playlet-lib/src/components/VideoFeed/VideoRowListRowContentJob.bs b/playlet-lib/src/components/VideoFeed/VideoRowListRowContentJob.bs index 9d852e0a..a89efca3 100644 --- a/playlet-lib/src/components/VideoFeed/VideoRowListRowContentJob.bs +++ b/playlet-lib/src/components/VideoFeed/VideoRowListRowContentJob.bs @@ -241,15 +241,11 @@ end function function HandleFeedLoadErrorDialog(error as object, isCancelled as boolean, rowList as object) as void error = ErrorUtils.Format(error) - if isCancelled - m.noTelemetry = true + LogErrorNoTelemetry(error) + else + LogError(error) end if - LogError(error) - if isCancelled - m.noTelemetry = false - end if - rowList.onError = error if rowList.hasField("dispose") and rowList.dispose return diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs index d314cb1b..ee75966f 100644 --- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs +++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs @@ -445,9 +445,7 @@ function OnVideoPlayerStateChange() as void errorInfo = m.top.errorInfo errorData = GetPlayerErrorData(content.videoId, errorInfo) - m.noTelemetry = true - LogError(errorData.title, errorData.body) - m.noTelemetry = false + LogErrorNoTelemetry(errorData.title, errorData.body) m.global.telemetry.LogEvent = { level: "error" message: errorData.title + `\n` + errorData.body @@ -501,9 +499,7 @@ function OnVideoPlayerStateChange() as void errorInfo = m.top.errorInfo errorData = GetPlayerErrorData(content.videoId, errorInfo) - m.noTelemetry = true - LogError(errorData.title, errorData.body) - m.noTelemetry = false + LogErrorNoTelemetry(errorData.title, errorData.body) m.global.telemetry.LogEvent = { level: "error" message: errorData.title + `\n` + errorData.body diff --git a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/HlsRouter.bs b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/HlsRouter.bs index 08342c54..c474b5ec 100644 --- a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/HlsRouter.bs +++ b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/HlsRouter.bs @@ -171,9 +171,7 @@ namespace Http end for if includedQualitiesCount = 0 - m.noTelemetry = true - LogWarn("No video streams found using quality filter:", qualityFilter, "Falling back to all video streams") - m.noTelemetry = false + LogWarnNoTelemetry("No video streams found using quality filter:", qualityFilter, "Falling back to all video streams") return hlsManifest end if return newLines.join(`\n`) diff --git a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs index 462ca2f7..16454ad9 100644 --- a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs +++ b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs @@ -214,9 +214,7 @@ namespace Http if not hasContinuation page = ValidString(request.query.page).ToInt() if page > 1 - m.noTelemetry = true - LogError("Playlet backend does not use history pagination (use continuation instead)") - m.noTelemetry = false + LogErrorNoTelemetry("Playlet backend does not use history pagination (use continuation instead)") response.Json({ "items": [] }) diff --git a/playlet-lib/src/components/Web/WebServer/Http/HttpConnection.bs b/playlet-lib/src/components/Web/WebServer/Http/HttpConnection.bs index 6fb043c6..3dbaa67b 100644 --- a/playlet-lib/src/components/Web/WebServer/Http/HttpConnection.bs +++ b/playlet-lib/src/components/Web/WebServer/Http/HttpConnection.bs @@ -165,9 +165,7 @@ namespace Http if m.socket.eSuccess() LogDebug(op + " peer closed @" + m.client) else - m.noTelemetry = true - LogError(op + " transfer error @" + m.client, m.socket.status()) - m.noTelemetry = false + LogErrorNoTelemetry(op + " transfer error @" + m.client, m.socket.status()) end if m.close = true m.SetState(Http.HttpConnectionState.DONE) diff --git a/playlet-lib/src/source/utils/Logging.bs b/playlet-lib/src/source/utils/Logging.bs index d33305d0..9e839684 100644 --- a/playlet-lib/src/source/utils/Logging.bs +++ b/playlet-lib/src/source/utils/Logging.bs @@ -9,10 +9,18 @@ function LogError(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 throw "FATAL: Calling LogError() which is a stub function" end function +function LogErrorNoTelemetry(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 = invalid as dynamic, _arg4 = invalid as dynamic, _arg5 = invalid as dynamic, _arg6 = invalid as dynamic, _arg7 = invalid as dynamic, _arg8 = invalid as dynamic, _arg9 = invalid as dynamic, _arg10 = invalid as dynamic, _arg11 = invalid as dynamic, _arg12 = invalid as dynamic, _arg13 = invalid as dynamic, _arg14 = invalid as dynamic, _arg15 = invalid as dynamic, _arg16 = invalid as dynamic) as void + throw "FATAL: Calling LogErrorNoTelemetry() which is a stub function" +end function + function LogWarn(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 = invalid as dynamic, _arg4 = invalid as dynamic, _arg5 = invalid as dynamic, _arg6 = invalid as dynamic, _arg7 = invalid as dynamic, _arg8 = invalid as dynamic, _arg9 = invalid as dynamic, _arg10 = invalid as dynamic, _arg11 = invalid as dynamic, _arg12 = invalid as dynamic, _arg13 = invalid as dynamic, _arg14 = invalid as dynamic, _arg15 = invalid as dynamic, _arg16 = invalid as dynamic) as void throw "FATAL: Calling LogWarn() which is a stub function" end function +function LogWarnNoTelemetry(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 = invalid as dynamic, _arg4 = invalid as dynamic, _arg5 = invalid as dynamic, _arg6 = invalid as dynamic, _arg7 = invalid as dynamic, _arg8 = invalid as dynamic, _arg9 = invalid as dynamic, _arg10 = invalid as dynamic, _arg11 = invalid as dynamic, _arg12 = invalid as dynamic, _arg13 = invalid as dynamic, _arg14 = invalid as dynamic, _arg15 = invalid as dynamic, _arg16 = invalid as dynamic) as void + throw "FATAL: Calling LogWarnNoTelemetry() which is a stub function" +end function + function LogInfo(_arg1 = invalid as dynamic, _arg2 = invalid as dynamic, _arg3 = invalid as dynamic, _arg4 = invalid as dynamic, _arg5 = invalid as dynamic, _arg6 = invalid as dynamic, _arg7 = invalid as dynamic, _arg8 = invalid as dynamic, _arg9 = invalid as dynamic, _arg10 = invalid as dynamic, _arg11 = invalid as dynamic, _arg12 = invalid as dynamic, _arg13 = invalid as dynamic, _arg14 = invalid as dynamic, _arg15 = invalid as dynamic, _arg16 = invalid as dynamic) as void throw "FATAL: Calling LogInfo() which is a stub function" end function diff --git a/tools/bs-plugins/logger-plugin.ts b/tools/bs-plugins/logger-plugin.ts index 0f390648..0a08ead3 100644 --- a/tools/bs-plugins/logger-plugin.ts +++ b/tools/bs-plugins/logger-plugin.ts @@ -22,18 +22,32 @@ const logFunctions = { LogError: { stringLevel: 'ERROR', level: 0, + telemetry: true + }, + LogErrorNoTelemetry: { + stringLevel: 'ERROR', + level: 0, + telemetry: false }, LogWarn: { stringLevel: 'WARN', level: 1, + telemetry: true + }, + LogWarnNoTelemetry: { + stringLevel: 'WARN', + level: 1, + telemetry: false }, LogInfo: { stringLevel: 'INFO', level: 2, + telemetry: false }, LogDebug: { stringLevel: 'DEBUG', level: 3, + telemetry: false } } @@ -164,7 +178,7 @@ export class LoggerPlugin implements CompilerPlugin { program.setFile(loggingFilePath, content) } - generateLoggingFunction(newFunctionName: string, level: string, argCount: number, isDebug: boolean) { + generateLoggingFunction(newFunctionName: string, originalFunctionName: string, argCount: number, isDebug: boolean) { const args: string[] = []; const argsParams: string[] = []; for (let i = 0; i < argCount; i++) { @@ -176,11 +190,11 @@ export class LoggerPlugin implements CompilerPlugin { return `ToString(${arg})`; }).join(` + " " + `); - const func = logFunctions[level as 'LogError' | 'LogWarn' | 'LogInfo' | 'LogDebug']; + const func = logFunctions[originalFunctionName as keyof typeof logFunctions]; let logLine = ''; - const telemetryEnabled = level === 'LogError' || level === 'LogWarn'; + const telemetryEnabled = func.telemetry; if (isDebug) { const RED = '[31m'; @@ -223,10 +237,7 @@ function ${newFunctionName}(${args.join(', ')}) as void logger.logLine = line `; if (telemetryEnabled) { - result += ` if not (m.noTelemetry = true) - m.global.telemetry.${level} = line - end if -`; + result += ` m.global.telemetry.${originalFunctionName} = line\n`; } result += `end function `;