# How to debug native errors? - Answered

**URL:** <https://forums.sui.io/t/how-to-debug-native-errors-answered/45078>\
**Category:** Technical Support\
**Tags:** sui\
**Created:** [October 24, 2023, 8:31am UTC](https://forums.sui.io/t/how-to-debug-native-errors-answered/45078 "2023-10-24T08:31:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GCB](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/gcb/32/16029_2.png) [@GCB](https://forums.sui.io/u/GCB)\
**Post date:** [October 24, 2023, 8:31am UTC](https://forums.sui.io/t/how-to-debug-native-errors-answered/45078/1 "2023-10-24T08:31:47Z")

</div>

I am having some challenges debugging this error.  
The error only shows up during a test. No Problems mentioned in vs code.  
Am I missing something obvious? The error occurs in borrow\_child\_object.

```auto
┌── test_user_journey_1 ──────
│ error[E11001]: test failure
│ ┌─ /..../sui-framework/packages/sui-framework/sources/dynamic_field.move:217:31
│ │
│ 217 │ public(friend) native fun borrow_child_object<Child: key>(object: &UID, id: address): &Child;
│ │ ^^^^^^^^^^^^^^^^^^^
│ │ │
│ │ Test was not expected to error, but it aborted with code 1 originating in the module 0x2::dynamic_field rooted here
│ │ In this function in 0x2::dynamic_field
│ 
│ 
│ stack trace
│ table::borrow(.../table.move:54)

```

code:

```auto
let votes_given = table::borrow(              
           &proposal_register.votes_by_user_counters, 
           voter_addr,
);

```

---

<div class="post-metadata">

**Author:** ![GCB](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/gcb/32/16029_2.png) [@GCB](https://forums.sui.io/u/GCB)\
**Post date:** [October 24, 2023, 8:34am UTC](https://forums.sui.io/t/how-to-debug-native-errors-answered/45078/2 "2023-10-24T08:34:01Z")

</div>

Answer from Damir on telegram:  
One tip at debugging most of the native errors. We usually add error constants in modules to mark abort codes.

 ![photo_5310177439290348426_y](https://europe1.discourse-cdn.com/sui/original/3X/8/f/8fdf3c06e8bf0f54dea292dde5c865612b884e2b.jpeg)  
As you can see from the codes descriptions, 1 stands for missing dynamic field, which means that you’re tying to borrow a field that doesn’t exist.

Generally we recommend adding an existence check for every borrow / borrow\_mut / remove you have and choose and add a custom abort code, so you don’t get this error in a function 100 lines long which calls other functions and modules and so on.

---

<div class="post-metadata">

**Author:** ![GCB](https://dub1.discourse-cdn.com/sui/user_avatar/forums.sui.io/gcb/32/16029_2.png) [@GCB](https://forums.sui.io/u/GCB)\
**Post date:** [October 24, 2023, 8:39am UTC](https://forums.sui.io/t/how-to-debug-native-errors-answered/45078/3 "2023-10-24T08:39:18Z")

</div>

The solution ended up being quite straightforward. Knowing now that the 1 means EFieldDoesNotExist.  
I figured that a check was required for the existence of the key, and adding the key if required.

```auto
// check if the voter_addr exists in the votes_by_user_counters
if ( !table::contains(&proposal_register.votes_by_user_counters, voter_addr) ) {
   // if not, add the voter_addr to the votes_by_user_counters
   table::add(&mut proposal_register.votes_by_user_counters, voter_addr, 0);
};

```
