# Error handling of Databin

I am using Databin in a FormFunction and would like to check whether the DatabinAdd[] was successful. If it is not I get a \$Failed but I am unable to check for it. Opening the non existing Databin err = Databin["13X7XXXJH"] will result in an error and the output Failed. As expected. Using FailureQ[err] gives however the wrong result False. err ===$Failed


Results also in False, while

err == $Failed  Results in \$Failed == \$Failed. How can I check whether a Databin command has been successful? ## 1 Answer Databin does not evaluate when the bin does not exist. Calling it with an invalid id err = Databin["13X7XXXJH"]  does not result in err=$Failure as one might expect but rather remains unevaluated as Databin["13X7XXXJH"] and calling err again results in the at this point already issued error message. For checking validity of a bin this is as discovered in this question rather unpleasant. I tried using Check, FailureQ, etc. without success. To be honest I am not sure if Databin is implemented correctly/properly in this regard because the output after Databin::apierr strongly suggests err=$Failure. I proceed by looking under the hood of Databin using PrintDefinitions from the GeneralUtilities package and I found the subroutine which checks id strings for validity: err=Catch@DataDropClientPrivategetBinID["13X7XXXJH"]  evaluates to $Failed with the specific error message Databin::nobin. Using getBinID one can define

DatabinCheck[s_String]:=Catch@Quiet[DataDropClientPrivategetBinID[s],Databin::nobin]


which returns a complete UUID string if s is the id of an existing Databin and \$Failed (without printing and error message) if s is invalid. One might use StringQ or FailureQ on the result to check it. Another option would be to use something like

DatabinCheck[s_String]:=Quiet[Check[Catch@DataDropClientPrivategetBinID[s],failexpr,Databin::nobin],Databin::nobin]


to return (or call) failexpr directly from within DatabinCheck.

Using the internal method getBinID might introduce some overhead and might not be very robust (given that it is an internal function which might/is change/d in future/past versions). Catching the Databin::apierr thrown by Databin itself seems much more elegant but I could not get this to work as discussed earlier.

• Thanks for your help. I suspect that FailureQ not working is a bug with Databin. I don't think I can use internals as the form is deployed to the cloud. I will try however. Apr 28, 2022 at 23:52