# 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`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://scope.onepub.dev/fundamentals/debugging.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
