# Node.spin() return non-zero error code at the correct work

**URL:** <https://forum.opencyphal.org/t/node-spin-return-non-zero-error-code-at-the-correct-work/341>\
**Category:** LibCyphal\
**Created:** [February 1, 2019, 10:17am UTC](https://forum.opencyphal.org/t/node-spin-return-non-zero-error-code-at-the-correct-work/341 "2019-02-01T10:17:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![EgoPingvina](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/e/edb3f5/32.png) [@EgoPingvina](https://forum.opencyphal.org/u/EgoPingvina)\
**Post date:** [February 1, 2019, 10:17am UTC](https://forum.opencyphal.org/t/node-spin-return-non-zero-error-code-at-the-correct-work/341/1 "2019-02-01T10:17:40Z")

</div>

I use method spin from `uavcan::Node` class like this:

```auto
static constexpr unsigned nodeMemoryPoolSize = 16384; // 4KB - 512KB
	
typedef uavcan::Node<nodeMemoryPoolSize> Node;

Node& GetNode()
{
	static Node mynode(GetCanDriver(), uavcan_stm32::SystemClock::instance());
	return mynode;
}

void NodeSpin() 
{
	int32_t errorCode;
	if ((errorCode= GetNode().spin(uavcan::MonotonicDuration::fromMSec(100))) != 0)
		ErrorHandler( __LINE__ );
}

```

In `errorCode` located value 1. I stopped at the breakpoint in `IF` and looked at the call stack to understand where this value came from. This 1 comes from the method `receive` in `uc_stm32_can.cpp`:

```auto
uavcan::int16_t CanIface::receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic,
                                  uavcan::UtcTime& out_ts_utc, uavcan::CanIOFlags& out_flags)
{
    out_ts_monotonic = clock::getMonotonic(); // High precision is not required for monotonic timestamps
    uavcan::uint64_t utc_usec = 0;
    {
        CriticalSectionLocker lock;
        if (rx_queue_.getLength() == 0)
        {
            return 0;
        }
        rx_queue_.pop(out_frame, utc_usec, out_flags);
    }
    out_ts_utc = uavcan::UtcTime::fromUSec(utc_usec);
    return 1;
}

```

And the most question is - why `recieve` return 0 then `rx_queue` is empty and 1 in other case(which is also the correct situation), although the 1 is an error code from `error.hpp`:  
`const int16_t ErrFailure = 1; ///< General failure`

Or errors are only negative error codes?

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [February 1, 2019, 11:02am UTC](https://forum.opencyphal.org/t/node-spin-return-non-zero-error-code-at-the-correct-work/341/2 "2019-02-01T11:02:17Z")

</div>

You should read the documentation 😉

> <https://github.com/OpenCyphal-Garage/libcyphal/blob/67da0aae7dd4eedae7905ab98941592cebab4723/libuavcan/include/uavcan/node/abstract_node.hpp#L68-L74>

A negative return value represents an error; a non-negative value represents a success. Non-negative values come from here, representing the number of CAN frames that were processed during the call:

> <https://github.com/OpenCyphal-Garage/libcyphal/blob/67da0aae7dd4eedae7905ab98941592cebab4723/libuavcan/src/transport/uc_dispatcher.cpp#L221-L250>

> [@EgoPingvina](#):
>
> Or errors are only negative error codes?

Correct.
