0
$\begingroup$

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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@DataDropClient`Private`getBinID["13X7XXXJH"]

evaluates to $Failed with the specific error message Databin::nobin. Using getBinID one can define

DatabinCheck[s_String]:=Catch@Quiet[DataDropClient`Private`getBinID[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@DataDropClient`Private`getBinID[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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Matariki
    Apr 28 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.