{"record":{"id":"a184cd73811246df","repo":"angular/angular.js","slug":"unknown-mode-only-log-rethrow-modes-are","errorCode":null,"errorMessage":"Unknown mode '{}', only 'log'/'rethrow' modes are allowed!","messagePattern":"Unknown mode '(.+?)', only 'log'/'rethrow' modes are allowed!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ngMock/angular-mocks.js","lineNumber":403,"sourceCode":"\n    switch (mode) {\n      case 'log':\n      case 'rethrow':\n        var errors = [];\n        handler = function(e) {\n          if (arguments.length === 1) {\n            errors.push(e);\n          } else {\n            errors.push([].slice.call(arguments, 0));\n          }\n          if (mode === 'rethrow') {\n            throw e;\n          }\n        };\n        handler.errors = errors;\n        break;\n      default:\n        throw new Error('Unknown mode \\'' + mode + '\\', only \\'log\\'/\\'rethrow\\' modes are allowed!');\n    }\n  };\n\n  this.$get = function() {\n    return handler;\n  };\n\n  this.mode('rethrow');\n};\n\n\n/**\n * @ngdoc service\n * @name $log\n *\n * @description\n * Mock implementation of {@link ng.$log} that gathers all logged messages in arrays\n * (one array per logging level). These arrays are exposed as `logs` property of each of the","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/angular/angular.js/blob/d8f77817eb5c98dec5317bc3756d1ea1812bcfbe/src/ngMock/angular-mocks.js#L385-L421","documentation":"ngMock replaces the $log provider with one whose mode(mode) setter accepts exactly two strategies: 'log' (collect every message into per-level arrays) and 'rethrow' (collect and also rethrow errors). Any other truthy value falls through the switch to the default branch and throws, so misconfiguration fails fast at setup time instead of silently doing nothing.","triggerScenarios":"Calling $logProvider.mode() (or the mock's provider) with a typo or invented name such as 'throw', 'silent', 'none', 'warn', 'strict'; passing a variable whose value is an unexpected string.","commonSituations":"Trying to silence noisy test output with an imagined mode like 'silent' or 'off'; porting test setup from another logging library whose mode names differ; passing undefined is tolerated (the setter only switches when mode is truthy), so only concrete wrong strings trigger it.","solutions":["Use 'log' to collect messages for later assertions, or 'rethrow' to also make logged errors fail the test.","To suppress console noise in tests, do not invent a mode — use $log.reset() after asserting, or $logProvider.debugEnabled(false) for debug-level output.","Check for typos/casing in the mode string ('Log', 'RETHROW' will throw — the comparison is exact)."],"exampleFix":"// before\nbeforeEach(module(function($logProvider) {\n  $logProvider.mode('silent'); // throws: unknown mode\n}));\n\n// after\nbeforeEach(module(function($logProvider) {\n  $logProvider.mode('log'); // collect into $log.error.logs etc.\n}));","handlingStrategy":"type-guard","validationCode":"var VALID_LOG_MODES = ['log', 'rethrow'];\nif (VALID_LOG_MODES.indexOf(mode) === -1) {\n  throw new Error('mode must be one of ' + VALID_LOG_MODES.join('/') + ', got: ' + mode);\n}\n$logProvider.mode(mode);","typeGuard":"function isValidLogMode(mode) {\n  return mode === 'log' || mode === 'rethrow';\n}","tryCatchPattern":null,"preventionTips":["Centralize the $log mode choice in one test helper instead of repeating the string.","Treat any 'make logs silent' need as $log.reset() or debugEnabled(false), never an invented mode."],"tags":["angular-mocks","logging","configuration","invalid-value"],"backgroundTag":"invalid-config-enum-value","analyzedSha":"d8f77817eb5c98dec5317bc3756d1ea1812bcfbe","analyzedAt":"2026-08-21T20:36:31.651Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}