Class @ember/debug

Show:

Available since v1.0.0

import { assert } from '@ember/debug';
desc
String
A description of the assertion. This will become the text of the Error thrown if the assertion fails.
test
Boolean
Must be truthy for the assertion to pass. If falsy, an exception will be thrown.

Define an assertion that will throw an exception if the condition is not met.

  • In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build.
1
2
3
4
5
6
7
import { assert } from '@ember/debug';

// Test for truthiness
assert('Must pass a valid object', obj);

// Fail unconditionally
assert('This code path should never be run');
import { debug } from '@ember/debug';
message
String
A debug message to display.

Display a debug notice.

  • In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build.
1
2
3
import { debug } from '@ember/debug';

debug('I\'m a debug notice!');

Available since v2.1.0

import { registerDeprecationHandler } from '@ember/debug';
handler
Function
A function to handle deprecation calls.

Allows for runtime registration of handler functions that override the default deprecation behavior. Deprecations are invoked by calls to Ember.deprecate. The following example demonstrates its usage by registering a handler that throws an error if the message contains the word "should", otherwise defers to the default handler.

1
2
3
4
5
6
7
8
Ember.Debug.registerDeprecationHandler((message, options, next) => {
  if (message.indexOf('should') !== -1) {
    throw new Error(`Deprecation message with should: ${message}`);
  } else {
    // defer to whatever handler was registered before this one
    next(message, options);
  }
});

The handler function takes the following arguments:

  • message - The message received from the deprecation call.
  • options - An object passed in with the deprecation call containing additional information including:
    • id - An id of the deprecation in the form of package-name.specific-deprecation.
    • until - The Ember version number the feature and deprecation will be removed in.
  • next - A function that calls into the previously registered handler.

Available since v2.1.0

import { registerWarnHandler } from '@ember/debug';
handler
Function
A function to handle warnings.

Allows for runtime registration of handler functions that override the default warning behavior. Warnings are invoked by calls made to warn. The following example demonstrates its usage by registering a handler that does nothing overriding Ember's default warning behavior.

1
2
3
4
import { registerWarnHandler } from '@ember/debug';

// next is not called, so no warnings get the default behavior
registerWarnHandler(() => {});

The handler function takes the following arguments:

  • message - The message received from the warn call.
  • options - An object passed in with the warn call containing additional information including:
    • id - An id of the warning in the form of package-name.specific-warning.
  • next - A function that calls into the previously registered handler.

Available since v1.5.0

import { runInDebug } from '@ember/debug';
func
Function
The function to be executed.

Run a function meant for debugging.

  • In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build.
1
2
3
4
5
6
7
8
9
10
import Component from '@ember/component';
import { runInDebug } from '@ember/debug';

runInDebug(() => {
  Component.reopen({
    didInsertElement() {
      console.log("I'm happy");
    }
  });
});

Available since v1.0.0

import { warn } from '@ember/debug';
message
String
A warning to display.
test
Boolean
An optional boolean. If falsy, the warning will be displayed.
options
Object
An object that can be used to pass a unique `id` for this warning. The `id` can be used by Ember debugging tools to change the behavior (raise, log, or silence) for that specific warning. The `id` should be namespaced by dots, e.g. "ember-debug.feature-flag-with-features-stripped"

Display a warning with the provided message.

  • In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build.