{"record":{"id":"9974a067d1e786b9","repo":"SeleniumHQ/selenium","slug":"level-must-be-0","errorCode":null,"errorMessage":"Level must be >= 0","messagePattern":"Level must be >= 0","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/lib/logging.js","lineNumber":79,"sourceCode":" * APIs exposed by this module for it are non-frozen. This module will be\n * updated, possibly breaking backwards-compatibility, once logging is\n * officially defined by the\n * [W3C WebDriver spec](http://www.w3.org/TR/webdriver/).\n */\n\n/**\n * Defines a message level that may be used to control logging output.\n *\n * @final\n */\nclass Level {\n  /**\n   * @param {string} name the level's name.\n   * @param {number} level the level's numeric value.\n   */\n  constructor(name, level) {\n    if (level < 0) {\n      throw new TypeError('Level must be >= 0')\n    }\n\n    /** @private {string} */\n    this.name_ = name\n\n    /** @private {number} */\n    this.value_ = level\n  }\n\n  /** This logger's name. */\n  get name() {\n    return this.name_\n  }\n\n  /** The numeric log level. */\n  get value() {\n    return this.value_\n  }","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/lib/logging.js#L61-L97","documentation":"Thrown by the Level constructor (logging.js) when a custom log level is created with a negative numeric value. Log levels are ordered by non-negative numeric severity (OFF=Infinity down to ALL=0), so negatives are meaningless. It is a TypeError, not a WebDriver protocol error.","triggerScenarios":"new logging.Level('CUSTOM', -1); computing a level from user input or a delta without clamping, e.g. new Level(name, base.value - offset) where offset exceeds base.","commonSituations":"Subtracting severities to derive a 'quieter' level and going below zero; reading a level number from env/config that defaults to -1 as a sentinel; porting code from a library whose levels start at 1.","solutions":["Use a non-negative value: new logging.Level('CUSTOM', 500).","Clamp derived values: Math.max(0, base - offset).","Reuse the built-in constants (Level.DEBUG/INFO/WARNING/SEVERE/OFF/ALL) instead of constructing custom levels.","Validate config input is a finite non-negative number before constructing the Level."],"exampleFix":"// before\nconst lvl = new logging.Level('trace', base.value - 1000); // can be negative\n\n// after\nconst lvl = new logging.Level('trace', Math.max(0, base.value - 1000));","handlingStrategy":"validation","validationCode":"function makeLevel(name, value) {\n  if (!Number.isFinite(value) || value < 0) {\n    throw new TypeError(`level value must be a finite non-negative number, got ${value}`);\n  }\n  return new logging.Level(name, value);\n}","typeGuard":"function isValidLevelValue(v) {\n  return typeof v === 'number' && Number.isFinite(v) && v >= 0;\n}","tryCatchPattern":"try {\n  return new logging.Level(name, derived);\n} catch (e) {\n  if (e instanceof TypeError && /Level must be >= 0/.test(e.message)) {\n    return new logging.Level(name, Math.max(0, derived));\n  }\n  throw e;\n}","preventionTips":["Clamp derived levels with Math.max(0, x).","Prefer built-in Level constants over custom ones.","Treat -1 sentinels from config as 'unset' and map to a real level."],"tags":["logging","validation","typeerror","configuration"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}