# Debugging

The Scope package is generally very easy to use as it works as expected in almost all cases.

### debugName

For the times when you are having problems, you can pass a `debugName` to each `Scope` and `ScopeKey`.

{% hint style="success" %}
If you are having problems debugging a Scope issue, start by adding a unique debugName to every Scope and ScopeKey.
{% endhint %}

We recommend that you pass the `debugName` to all your Scope's and ScopeKeys. It will make debugging problems much easier if you get into the habit.

```dart
final key = ScopeKey<int>('debug key name');

Scope('debug scope name')
..value(key, 1);
```

When running in the debugger the `debugName` will be displayed.

You can also print out the `debugName` for a `ScopeKey` or `Scope` by calling their `toString()` method.

### Nested Scopes

Probably the most complex situation is when you have nested Scopes.  Check the call stack for multiple Scope instances.

When you call `use` within a Nested Scope it will search 'up' the call stack looking for the first Scope. If the key is found in that Scope then that value is returned. If the key isn't found we keep searching up the stack for additional Scopes.

The methods `withinScope` and `hasScopeKey` can also help debugging problems when calling `use`.
