samuelpowell / Spinnaker.jl

A Julia interface to the FLIR/PointGrey Spinnaker SDK
MIT License
15 stars 7 forks source link

Add SpinError exception type to propagate error value #75

Closed IanButterworth closed 3 years ago

IanButterworth commented 3 years ago

Adds a SpinError exception type with a val field, such that the Spinnaker SDK spinError enum value can be saved and compared. Currently the ErrorException that is returned has to be string compared via the msg field, which is suboptimal.

Should be a breaking change release.

Errors will still show the same way.

julia> reset!(cam); start!(cam)
ERROR: Spinnaker SDK error: SPINNAKER_ERR_NOT_INITIALIZED(-1002)
Stacktrace:
 [1] checkerror
   @ ~/.julia/dev/Spinnaker/src/Spinnaker.jl:31 [inlined]
 [2] spinCameraBeginAcquisition
   @ ~/.julia/dev/Spinnaker/src/wrapper/spin_api.jl:321 [inlined]
 [3] start!(cam::Camera)
   @ Spinnaker ~/.julia/dev/Spinnaker/src/camera/acquisition.jl:23
 [4] top-level scope
   @ REPL[18]:1

But they can be caught and value compared

julia> try
         reset!(cam)
         start!(cam)
       catch ex
         if ex isa SpinError
            ex.val == Spinnaker.SPINNAKER_ERR_NOT_INITIALIZED && println("gotcha")
         end
       end
gotcha
samuelpowell commented 3 years ago

Does spinError come from C land? Is it an int?

IanButterworth commented 3 years ago

It's an alias for the @cenum https://github.com/samuelpowell/Spinnaker.jl/blob/6073897755edc436714ec5d1f3d727cf257c1e3a/src/wrapper/spin_common.jl#L3297-L3342

julia> typeof(Spinnaker.SPINNAKER_ERR_NOT_INITIALIZED)
Spinnaker._spinError
samuelpowell commented 3 years ago

Okay. Arbitrary question asked and answered. LGTM.