Thanks! You are right, I have tried another minimal statement and does not 
throw any exception... looks like the statement on that repo is not correct 
either (I don't know what's wrong with it), but don't know how to output 
proper error messages. According to the repo, 

(xs/validate-statement-data statement-str) ;; => returns statement edn

but I do not know what edn stands for. Moreover, I always have the argument 
as a plain string, not as an object as in this 
<https://github.com/yetanalytics/xapi-schema/blob/master/README.org#clojurescript>example.
 
I have read also this:

(xs/errors->data (xs/statement-checker bad-statement :en)))) ;; ltag is 
optional, defaults to :en
;; => {"actor" "Missing required key", "id" "Not a string: 123"}

but I am unclear of the meaning of -> and how to use that from Java. Looks 
like statement-checker is for objects, not for strings?

I have a minimal working example 
here: https://github.com/olbapjose/xapi-clojure

Regards and happy new year!



El martes, 26 de diciembre de 2017, 17:37:54 (UTC+1), Gary Verhaegen 
escribió:
>
> On 26 December 2017 at 14:54, Pablo J. Villacorta <olba...@gmail.com 
> <javascript:>> wrote:
>
>> Thank you so much guys.
>>
>> Yes, it is an error launched by the library, but with a statement that 
>> should be valid since I copied it from the github page of the project. It 
>> seems that the "@cec1ce2" means something but I don't know...
>> it is exactly this input statement: 
>> https://github.com/yetanalytics/xapi-schema/blob/master/README.org#validate-a-statement-from-a-json-string-clojurescript
>>
>
> The code you showed in your email explicitly calls
>
> myfunction.invoke("some string");
>
> which is the equivalent of the Clojure code
>
> (xs/validate-statement-data "some string")
>
> which is documented to throw an Exception by the README, in the Usage 
> section:
>
> (let [bad-statement (dissoc statement "actor")]
>   (xs/validate-statement-data bad-statement)) ;; => throws Exception or 
> js/Error
>
> If you look at the code for xs/validate-satement-data, you can see that 
> it pretty much reduces to calling xs/validate-statement, which itself 
> looks like:
>
> (defn validate-statement [s]
>   (if-let [error (statement-checker s)]
>     (throw #?(:clj (Exception. (str error))
>               :cljs (js/Error. (str error))))
>     s))
>
> See 
> https://github.com/yetanalytics/xapi-schema/blob/master/src/xapi_schema/core.cljc#L24-L29
>  
> for more context.
>
> So what I think has happened is that you have given an invalid string to 
> the function ("some string"), so it is throwing a java.lang.Exception 
> with, as its message, the result of calling clojure.lang/str on the error 
> returned by the schema library. That error is a Java object of a class that 
> clojure.lang/str doesn't know about, so it falls back to calling the Java 
> method toString. As the schema.utils.NamedError class does not implement 
> (override) toString, this falls back to java.lang.Object#toString(), 
> which prints the name of the class followed by some random-looking hex 
> value that is supposed to be somehow linked to the place of the object in 
> memory (except that number doesn't change when the GC moves the object, so 
> it's more some sort of identity than an address).
>
> If you also get a stack trace when you do pass expectedly valid data to 
> the function, can you prepare a minimal Github project with the code that 
> fails? I can't see anything wrong in your descriptions so far so I'd need 
> to look at the exact code you're trying to run to help you further.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to