Datomic error message - clojure

I'm getting this when I'm calling transact:
datomic.impl.Exceptions$IllegalArgumentExceptionInfo: :db.error/not-a-data-function Not a data function: 71
data: {:db/error :db.error/not-a-data-function}
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: :db.error/not-a-data-function Not a data function: 71
What is the error message trying to tell me? I don't have '71' in my data anywhere, so ah, um... Yeah. This takes clojure stack traces to a new level.

Datomic supports database functions. So let's say you installed a database function called ":foo/bar" you would call it in a transaction thusly:
[[:foo/bar arg1 arg2 ...]]
What this error is saying is that it thinks you are calling a database function, but that function does't exist. In this case it thinks that function name is 71.
Take a look at the data you are transacting and make sure it is in the correct format. For example, I've seen this error when passing a map as {:my/key 42} instead of [{:my/key 42}]. The input of transact should always be a sequence of data, even if all you are transacting is a hashmap.

Related

findRecord() returns error but record is returned properly

I have a strange error when calling data store's findRecord() function. Below is the function call inside of a route,
return this.get('store').findRecord('restaurant', params.restaurant_id);
And here are the errors I get,
vendor-6605726….js:10 Error while processing route: admin.restaurants.show e.getRecord is not a function TypeError: e.getRecord is not a function
vendor-6605726….js:8 TypeError: e.getRecord is not a function
The strangest thing is that the function works as it should since I can see using ember inspector that the query executes properly and returns the correct record. I have an index route that calls findAll() that does not throw any errors. I am formatting my json correctly I believe so I am out of ideas on what this could me.
Here is the json,
{"data":[{"type":"restaurants","id":1,"attributes":{"user_id":1,"name":"###########","address":"","phone":"##########","website":"##########","created_at":"2017-03-19 20:42:02","updated_at":"2017-03-19 20:42:02","description":"###########"}}]}
I recently had the same issue. It is highly likely that the JSON payload returned by your API isn't formatted correctly. Remember that findRecord() expects a single object to be returned, not an array:
{"data": {}}
not
{"data": []}
Double-check DevTools to see what your API returns to the client - make sure it's not an array.

NullPointerException [no message] -- how can I find its source?

I have NullPointerException [no message] in my luminus application. The code is quite long to post it here and I can't find the source of the error. Neither there's any mention of "NullPointerException [no message]" in the logs, and in the browser the error just doesn't make sense and the exact place and variables where the error is caused aren't shown precisely.
How can I trace what causes the error?
the approach that i take for such errors is
if it is a new error (started happening recently), then most probably it is being caused by the code that was added recently. so use that code as the starting point
see if there are any API calls which might be returning a nil value. try to replace every API w/ a real hardcoded value, one-by-one, and see if you're still seeing the error
once you figure out which API call is returning nil, then dig deeper to see if you're passing any wrong arguments to the API, or causing some case due to which it is returning the nil
HTH :)
Clojure's error messages can be hell but they aren't useless. Take a look at this link:
https://8thlight.com/blog/connor-mendenhall/2014/09/12/clojure-stacktraces.html
It helped me out and hope it can do the same for you
Null pointer exception is caused because of accessing / using a variable which holds the value. As a programmer we have to do null chuck to the variable which are returning a value from other functions.
If you want to trace it just keep debug point from which action you are getting this error n chuck which variable your accessing as null value.

How to deal with possible duplicates in an Ember store?

My Ember apps retrieves model objects from an API that can contain duplicates on successive calls.
I want to store my objects like this:
myController.store.createRecord('myModel', myModelObject).save()
Unfortunately, when a duplicate occurs, I get the following error in the console:
Error: Assertion Failed: The id XXX has already been used with another record of type MyApp.MyModel.
(fonction anonyme)ember.js:3866
I couldn't figure a way to recover gracefully from that error. I tried:
myController.store.createRecord('myModel', myModelObject).save().catch(myFailureCallback)
but the failure callback doesn't get called and the error is the same.
You could check to see if the record is already loaded into the store
http://emberjs.com/api/data/classes/DS.Store.html#method_recordIsLoaded
store.recordIsLoaded('myModel', myModelObject.get('id'))

the persisting records instructions in the guide don't work for me

I'm trying to use the instructions find here:
http://emberjs.com/guides/models/persisting-records/
My server receives the json well and creates a record which it then returns properly, but my onSuccess function doesn't get anything usable as a response. It gets this strange object which if I try to pass onto the next route like the instructions say, it errors out saying this:
Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed '' (wrapped in (generated articles.view controller))
Here is my code:
https://github.com/mgenev/Full-Stack-JS-Boilerplate/blob/master/public/ember/controllers/articles_controller.js
I appreciate any help.
It looks like your transitionToArticle function requires an argument but you're not passing in anything when you're calling it:
article.save().then(transitionToArticle).catch(failure);

Handle Invalid Data Type in CF Remote Function

So I have a remote ColdFusion Function like:
remote string function name (required numeric varname){
This is accessed via AJAX call. Google has taken it upon itself to pass in junk/blank values to the URL to this remote function. How can I gracefully handle those for Bots/Users to manage to get in a junk value. I've tried putting try/catch around/inside the function and doesn't work. I've also tried setting a default value but I still get an error. I'd like to be able to return an error message.
Thoughts?
Right now:
domain.com/path/to/page.cfc?method=function&varname=
Is throwing an error
domain.com/path/to/page.cfc?method=function&varname=5
Is working as expected.
Update:
I am leaving this here for posterity, as it explains the cause of the error and chain of events with validation. However, Adam's response is the correct solution IMO.
remote string function name (required numeric varname){
I've tried putting try/catch around/inside the function and doesn't work.
Because the argument value is validated before CF executes anything inside the function. So it never even gets to the try/catch.
If you want to allow non-numeric values, you must set the argument type to string and perform validation inside the function. ie
// use whatever check is appropriate here
if ( IsNumeric(arguments.varname) ) {
// good value. do something
}
else {
// bad value. do something else
}
I've also tried setting a default value but I still get an error
domain.com/path/to/page.cfc?method=function&varname=
Update
The reason it does not work is because the varname parameter does exists. Its value is an empty string. As long as some value is passed (even an empty string) the default is ignored.
I disagree that the accepted solution is the best approach here.
Firstly, if your method is expecting a numeric and it's being passed a string, then an error is precisely the correct reaction here. You shouldn't feel the need to mitigate for requests that pass invalid values. Consider it like someone making a request to http://some.domain/path/to/file/wrongOne.html (they should have requested http://some.domain/path/to/file/rightOne.html)... it's completely OK for things to return a 404 "error" there, isn't it? An error response is exactly right in that situation.
Similarly, you have dictated that for your remote call URL, that argument is supposed to be numeric. So if it's not numeric... that is an error condition. So your server returning a 500-type error is actually the correct thing to do.
This is an example of the "garbage in, garbage out" rule.
If you are looking for an elegant solution, I'd say you already have the most elegant solution. Don't mess around writing special code to deal with incorrectly made requests. That is not an elegant approach.
You are better off letting the thing error, because then the mechanism requesting the URL will stop doing it. Messing around so that you are returning a 200 OK for a request that wasn't "OK" is the wrong thing to do.
Errors - when they are the correct result - are fine. There's nothing wrong with them.