# Debug functions :::callout{theme="success"} The following documentation is specific to TypeScript v1 functions. For more [robust capabilities](../language-feature-support/index.md#typescript-v1-vs-typescript-v2), including support for Ontology SDK and configurable resource requests, we recommend [migrating to TypeScript v2](../typescript-v2-migration/index.md). ::: As you write functions, you will likely need to inspect the state of your execution to fix issues with code correctness or performance. Below are features you can use to do this. These debugging steps also apply to [unit tests](../unit-test-getting-started/index.md). ## Authoring debugger Use the debugger tool in Code Repositories to examine the behavior of your unit test while it runs. Set breakpoints to pause the execution of the unit test in order to examine variables, and understand functions and libraries. ![Debugger overview panel.](../../../assets/0679aa62a2637c9eb8ba55fdcfd41ac10771d989045101729e8e62d5133dc68d.webp) ## Set breakpoints To use the debugger, you need to set breakpoints. These breakpoints indicate the specific points where the debugger should pause the code execution, enabling you to interact with variables. Set a breakpoint by selecting the faded red dot in the margins of each line of code. The debugger suspends the execution *before* the marked line runs. You can set multiple breakpoints across several files, if needed. ![Debugger breakpoints.](../../../assets/d8c08711f312b7e6796647464e92ff2eaf1d9d2a15196167c1fb46d55442a566.webp) ## Run the debugger ### During live preview After adding breakpoints in your code, select **Run and debug**, located in the functions panel. ![Live preview debugger layout.](../../../assets/71c427c776933a5f00ffb04ac2cdd6fa874c3b2ef7ff9225343e90cff725b6e3.webp) ### During testing After adding breakpoints in your code, select **Run test**, located next to the unit test in the code editor. ![Test debugger layout.](../../../assets/453dc9de38af1d3a649e66b2d9060a890f869c7c9efcc0abaf9361c69cd82392.webp) ## Use the debugger Once the debugger has started, the debugger panel will open and pause on the first breakpoint it encounters. The left bar of the debugger allows you to navigate the code, remove breakpoints, and finish or stop the debugging session. As you navigate the code, the editor highlights the line of code to be executed next. Use the following buttons to advance the debugger: ![Debugger controls.](../../../assets/9d506af5e3dfb108e2b912bd6070f0f1fba435319c0d475c72b351db869289a6.webp) 1. **Resume execution:** Continue execution until completion or until paused by the next breakpoint. 2. **Step over:** Execute the line of code without stepping into internal functions. 3. **Step into:** Navigate into internal functions if they exist in that line of code. 4. **Step out:** Navigate out of an internal function and advance the debugger. 5. **Stop execution:** Stop the debugger completely. 6. **Remove breakpoints:** Remove all breakpoints from the repository and run the unit test without pausing the execution. 7. **Settings:** Toggle the debugger on/off (without clearing the breakpoints). 8. **Documentation:** Open the documentation for additional details. ## Examine variables While the debugger is running, you can examine the variables and data at the exact point of code execution. ### Frames Frames represent the functions in which the debugger is active or in which breakpoints exist. Each frame indicates the name of the function followed by the name of the file and the line number in which the function is written. Select a frame to examine the variables within that frame and run console commands against it. ### Variables The variables section displays the values stored in both local and global variables while the transform is executed. ![Debugger variables.](../../../assets/2862abd398e34e80a8fd4e5ff9e2fb69671e39b039af57d87909d5055a2c5eee.webp) ### Console The console allows you to interact with your data using JavaScript console commands while running the debugger. The console operates within the context of the selected frame, so attempting to execute commands on variables local to a different frame leads to an error. ![Debugger console.](../../../assets/47460987078353a00877c921217865fd30ff4e4662375bee2b97a5026c301db7.webp) ## Console logging Functions supports emitting console logs during execution for debugging purposes. To do so, simply use the `console.log` command to emit logs. For example: ```typescript @Function() public testConsoleLogging(n: Integer): Integer { for (let i = 0; i < n; i++) { console.log(`Iteration ${i}`); } return n; } ``` Using console logs in this way can be useful for debugging correctness issues. You can also add console logs to identify performance bottlenecks in your code. See the guide for [optimizing performance](../optimize-performance/index.md) for more information on how to improve the performance of link traversal logic. ### During testing When you run a function using the **Tests** helper in **Authoring**, console logs will be captured and displayed below: ![Console logging tests.](../../../assets/226797979c4425abbe6df45017beaa33154276cad47c7ef8993c787fb472c73c.webp) ### During live preview When you run a function using the **Functions** helper in **Authoring**, console logs will be captured and displayed below, along with timestamps: ![Console logging live preview.](../../../assets/3b4192295de6aa5dd1a40b8952e82605b405e516cc8011bc8b900f194a65d420.webp)