{"record":{"id":"6dee9c67e9bbd9fa","repo":"SeleniumHQ/selenium","slug":"not-a-string-or-number","errorCode":null,"errorMessage":"not a string or number","messagePattern":"not a string or number","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/lib/logging.js","lineNumber":196,"sourceCode":"  [Level.FINER.name, Level.FINER],\n  [Level.FINEST.name, Level.FINEST],\n  [Level.ALL.name, Level.ALL],\n])\n\n/**\n * Converts a level name or value to a {@link Level} value. If the name/value\n * is not recognized, {@link Level.ALL} will be returned.\n *\n * @param {(number|string)} nameOrValue The log level name, or value, to\n *     convert.\n * @return {!Level} The converted level.\n */\nfunction getLevel(nameOrValue) {\n  if (typeof nameOrValue === 'string') {\n    return LEVELS_BY_NAME.get(nameOrValue) || Level.ALL\n  }\n  if (typeof nameOrValue !== 'number') {\n    throw new TypeError('not a string or number')\n  }\n  for (let level of ALL_LEVELS) {\n    if (nameOrValue >= level.value) {\n      return level\n    }\n  }\n  return Level.ALL\n}\n\n/**\n * Describes a single log entry.\n *\n * @final\n */\nclass Entry {\n  /**\n   * @param {(!Level|string|number)} level The entry level.\n   * @param {string} message The log message.","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/lib/logging.js#L178-L214","documentation":"Thrown by getLevel() (logging.js) when its argument is neither a string nor a number — e.g. an object, array, undefined, boolean, or null. The function converts a level name or numeric value to a Level; anything else is a programming/type error. Returns Level.ALL for unrecognized but correctly-typed inputs, so this throw is specifically for wrong types.","triggerScenarios":"getLevel({name:'INFO'}), getLevel(undefined), getLevel(true), getLevel(null). Passing a logger instance or a config object instead of the level field. Note null is typeof 'object' so it hits this branch.","commonSituations":"Destructuring a config object and passing the whole object instead of a field; default parameter evaluates to undefined when the caller omits the arg; reading a value that may be missing and not defaulting.","solutions":["Pass a string name ('INFO') or a number (800).","Default the argument: getLevel(input ?? 'INFO').","Coerce: getLevel(typeof input === 'number' ? input : String(input)).","Guard upstream with typeof input === 'string' || typeof input === 'number'."],"exampleFix":"// before\nconst lvl = logging.getLevel(config.logging); // config.logging is an object\n\n// after\nconst lvl = logging.getLevel(config.logging?.level ?? 'INFO');","handlingStrategy":"type-guard","validationCode":"function safeGetLevel(nameOrValue) {\n  if (typeof nameOrValue !== 'string' && typeof nameOrValue !== 'number') {\n    return logging.Level.ALL; // or throw\n  }\n  return logging.getLevel(nameOrValue);\n}","typeGuard":"function isLevelNameOrValue(x) {\n  return typeof x === 'string' || typeof x === 'number';\n}","tryCatchPattern":"try {\n  level = logging.getLevel(input);\n} catch (e) {\n  if (e instanceof TypeError && /not a string or number/.test(e.message)) {\n    level = logging.Level.ALL;\n  } else throw e;\n}","preventionTips":["Default optional args: getLevel(input ?? 'INFO').","Pass the field, not the config object: cfg.level not cfg.","Validate typeof at the boundary where external data enters."],"tags":["logging","type-validation","typeerror","configuration"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}