Skip to content

Commit

Permalink
Improved exception when not running as root (#564)
Browse files Browse the repository at this point in the history
When RF24 wasn't ran as root, it threw a very cryptic error (see #531): `terminate called after throwing an instance of 'int'`

This commit will improve that and now it appears as: `terminate called after throwing an instance of 'std::runtime_error' what():  Process should run as root`
  • Loading branch information
CoRfr authored and Avamander committed Jan 27, 2020
1 parent f055f1d commit ebbdbf3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion utility/RPi/spi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "spi.h"
#include <pthread.h>
#include <unistd.h>
#include <stdexcept>

static pthread_mutex_t spiMutex = PTHREAD_MUTEX_INITIALIZER;
bool bcmIsInitialized = false;
Expand All @@ -24,7 +25,7 @@ void SPI::begin(int busNo)
void SPI::beginTransaction(SPISettings settings)
{
if (geteuid() != 0) {
throw -1;
throw std::runtime_error("Process should run as root");
}
pthread_mutex_lock(&spiMutex);
setBitOrder(settings.border);
Expand Down

0 comments on commit ebbdbf3

Please sign in to comment.