{"record":{"id":"741d00ab60ee05eb","repo":"pear-devs/pear-desktop","slug":"expected-linear-logarithmic-or-a-positive-num","errorCode":null,"errorMessage":"Expected 'linear', 'logarithmic' or a positive number as fade scaling preference!","messagePattern":"Expected 'linear', 'logarithmic' or a positive number as fade scaling preference!","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/plugins/crossfade/fader.ts","lineNumber":141,"sourceCode":"        options.fadeScaling === undefined ||\n        options.fadeScaling === 'logarithmic'\n      ) {\n        // Set default of 60 dB\n        dynamicRange = 3;\n      }\n      // Custom dynamic range?\n      else if (\n        typeof options.fadeScaling === 'number' &&\n        !Number.isNaN(options.fadeScaling) &&\n        options.fadeScaling > 0\n      ) {\n        // Turn amplitude dB into a multiple of 10 power dB\n        dynamicRange = options.fadeScaling / 2 / 10;\n      }\n      // Unsupported value\n      else {\n        // Abort and throw exception\n        throw new TypeError(\n          \"Expected 'linear', 'logarithmic' or a positive number as fade scaling preference!\",\n        );\n      }\n\n      // Use exponential/logarithmic scaler for expansion/compression\n      this.scale = {\n        internalToVolume: (level: number) =>\n          this.exponentialScaler(level, dynamicRange),\n        volumeToInternal: (level: number) =>\n          this.logarithmicScaler(level, dynamicRange),\n      };\n\n      // Log setting if not default\n      if (options.fadeScaling)\n        this.logger?.(\n          'Using logarithmic fading with ' +\n            String(10 * dynamicRange) +\n            ' dB dynamic range.',","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/pear-devs/pear-desktop/blob/1e2aac5706c870c93ed74ba8727ae8390d3b0fa5/src/plugins/crossfade/fader.ts#L123-L159","documentation":"VolumeFader's options.fadeScaling accepts only the string 'linear', the string 'logarithmic' (or undefined, both meaning 60 dB default), or a positive finite number interpreted as a custom dynamic range in amplitude-dB. Any other value — strings like 'log', 0, negative numbers, NaN, null — throws this TypeError from the constructor.","triggerScenarios":"Passing {fadeScaling: 'log'} or {fadeScaling: 'exp'}; passing 0 or a negative dB value; passing NaN or null because of an unguarded config field; typos in config keys from user settings files.","commonSituations":"User-editable plugin settings where a free-text scaling preference is typed in ('LOG', 'logarithmic ' with whitespace); migrating config between versions where the value became null; copy-pasting example config that uses an unsupported shorthand.","solutions":["Use exactly 'linear', 'logarithmic', or a positive number (e.g. 60 for 60 dB range)","Sanitize user config before constructing: trim/lowercase strings and reject or default unknown values","Validate with a helper (see type guard) so bad settings fall back to the logarithmic default instead of crashing the player"],"exampleFix":"// before\nnew VolumeFader(media, { fadeScaling: 'log' }); // throws\n\n// after\nconst scaling = ['linear','logarithmic'].includes(cfg.fadeScaling) || (typeof cfg.fadeScaling === 'number' && cfg.fadeScaling > 0)\n  ? cfg.fadeScaling\n  : 'logarithmic';\nnew VolumeFader(media, { fadeScaling: scaling });","handlingStrategy":"validation","validationCode":"const FADE_SCALINGS = ['linear', 'logarithmic'] as const;\nconst parseScaling = (v: unknown) =>\n  v === 'linear' || v === 'logarithmic' ? v\n  : typeof v === 'number' && Number.isFinite(v) && v > 0 ? v\n  : 'logarithmic'; // safe default","typeGuard":"const isFadeScaling = (v: unknown): v is 'linear' | 'logarithmic' | number =>\n  v === 'linear' || v === 'logarithmic' ||\n  (typeof v === 'number' && Number.isFinite(v) && v > 0);","tryCatchPattern":"try { new VolumeFader(media, { fadeScaling: cfg.fadeScaling }); } catch (e) { if (e instanceof TypeError && /fade scaling/.test(e.message)) new VolumeFader(media); /* defaults */ else throw e; }","preventionTips":["Use a select/dropdown for fadeScaling in settings UI, not free text","Whitelist config values before constructing the fader","Treat unknown config values as 'use default', not crash"],"tags":["crossfade","validation","typeerror","configuration","enum"],"backgroundTag":"invalid-configuration-value","analyzedSha":"1e2aac5706c870c93ed74ba8727ae8390d3b0fa5","analyzedAt":"2026-08-27T20:01:08.614Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}