SwiftyGPIO icon indicating copy to clipboard operation
SwiftyGPIO copied to clipboard

Don't hard-crash when `/dev/mem` can't be opened

Open helje5 opened this issue 7 years ago • 4 comments

Currently you quickly run into a

Fatal error: Can't open /dev/mem , use sudo!: file ../.build/checkouts/SwiftyGPIO.git-1203819502/Sources/SwiftyGPIO.swift, line 353

when a tool is started w/o sudo.

Since that is so common, I would rather provide a proper API for that (probably something throwing an Error). The (user)-dev should handle that case, and provide a clean exit.

helje5 avatar Jun 14 '18 11:06 helje5

Yeah, it makes sense when swifygpio is just used in a subsystem and the application should continue to work regardless of gpio failures. I'll take a look at it, since GPIO objects are pre-initialized in the presets I'll likely turn those read/write methods into throwing methods and reorganize those checks.

uraimo avatar Jun 18 '18 06:06 uraimo

What is the status of this requested change? I would like to see something other than abort in the I2C module as well. I do not want to have my system taken down due to an I2C bus problem that impacts system functionality but it should not keep the remaining system components from operating.

Maybe it could return a Result type in its place which returns the data or an error depending on outcome?

MotivDev avatar May 08 '19 19:05 MotivDev

I will do a new release tomorrow or so and the refactor of the error handling will be one of the changes included 👍

uraimo avatar May 08 '19 19:05 uraimo

@MotivDev The next_release branch should already have what you need, for the original request of this issue I'll add and optional, and not really nice to look at, way to check if a GPIO/PWM is usable shortly.

Note: SPM should ignore the format of these -beta tags and use the last 2.0.0-??? tag if you set that release in your descriptor (if not, it's a bug).

Note2: This new branch contains other unrelated changes, so you'll likely need to update your code for them, sorry.

Note3: Use "2.0.0-beta2" as version tag (or whatever is the latest one) in your Package.swift ...

uraimo avatar May 12 '19 19:05 uraimo