fix: imlprove debug formatters
Some checks are pending
Check / check (push) Waiting to run

This commit is contained in:
ThaUnknown 2025-07-27 19:23:18 +02:00
parent 967ad751b4
commit b73ee4a841
No known key found for this signature in database
6 changed files with 26 additions and 8 deletions

View file

@ -1,6 +1,6 @@
{
"name": "ui",
"version": "6.4.90",
"version": "6.4.91",
"license": "BUSL-1.1",
"private": true,
"packageManager": "pnpm@9.15.5",

View file

@ -30,7 +30,7 @@ class AnilistClient {
// hacky but prevents query from re-running
// the debug logging is added after an empty useless subscription, don't delete this subscription!
this.userlists.subscribe(ids => {
debug('userlists: ', ids?.data?.MediaListCollection)
debug('userlists: ', ids?.data?.MediaListCollection?.lists?.find(list => list?.status === 'CURRENT')?.entries?.map(entry => entry?.media?.id) ?? [])
})
this.continueIDs.subscribe(ids => {
debug('continueIDs: ', ids)

View file

@ -325,7 +325,7 @@ export default new class URQLClient extends Client {
})
this.limiter.on('failed', async (error: FetchError | Error, jobInfo) => {
debug('Bottleneck onfailed', error, jobInfo)
debug('Bottleneck onfailed', error, jobInfo.options, jobInfo.retryCount, jobInfo.args[0], jobInfo.args[1]?.body)
// urql has some weird bug that first error is always an AbortError ???
if (error.name === 'AbortError') return undefined
if (jobInfo.retryCount > 8) return undefined

View file

@ -10,7 +10,7 @@ const _debug = Debug('ui:settings')
export const settings = persisted('settings', defaults, { beforeRead: value => ({ ...defaults, ...value }) })
export const debug = persisted('debug', '')
export const debug = persisted('debug-key', '')
debug.subscribe((value) => {
native.debug(value)

View file

@ -63,7 +63,7 @@ export const server = new class ServerClient {
const last = get(this.last)
if (last) {
this.play(last.id, last.media, last.episode)
debug('restored last torrent', last.id, last.media.title, last.episode)
debug('restored last torrent', last.id, last.media.title?.userPreferred, last.episode)
}
this.stats.subscribe((stats) => {

View file

@ -9,6 +9,7 @@ import humanize from 'ms'
const exports = {}
const module = { exports }
const formatters = {}
exports.formatArgs = formatArgs
exports.save = save
@ -16,6 +17,7 @@ exports.load = load
exports.humanize = humanize
exports.useColors = useColors
exports.storage = localstorage()
exports.formatters = formatters
exports.destroy = (() => {
let warned = false
@ -33,8 +35,6 @@ exports.destroy = (() => {
exports.colors = [6, 2, 3, 4, 5, 1]
const { formatters = {} } = module.exports
/**
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
* and the Firebug extension (any Firefox version) are known
@ -153,6 +153,16 @@ formatters.j = function (v) {
}
}
formatters.O = function (v) {
try {
return v && typeof v === 'object' ? JSON.stringify(v, null, 2) : v
} catch (error) {
return '[UnexpectedJSONParseError]: ' + error.message
}
}
formatters.o = formatters.j
/**
* This is the common logic for both the Node.js and web browser
* implementations of `debug()`.
@ -184,7 +194,7 @@ function setup (env) {
*
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
*/
createDebug.formatters = {}
createDebug.formatters = formatters
/**
* Selects a color for a debug namespace
@ -238,8 +248,16 @@ function setup (env) {
if (typeof args[0] !== 'string') {
// Anything else let's inspect with %O
args.unshift('%O')
} else {
for (let i = 1; i < args.length; i++) {
if (typeof args[i] === 'object') {
args[0] += ' %j'
}
}
}
// Apply any `formatters` transformations
let index = 0
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {