Cannot convert value to bool : InvalidArgumentException - cakephp-3.3

I am using cakephp 3.3 for my vod application and i want to insert data using following query:
$query=$notifications->query()->insert(['message' ,'status','user_id' ,'video_id' ,'notify_to' ,'notification_type'])
->values([
'message'=>'Congratulations! your video '.$video_name.' has been approved to be uploaded on MM2View by admin.',
'status'=>$status,
'user_id'=>$user_id[0]['users_id'],
'video_id'=>$id,
'notify_to'=>1,
'notification_type'=>3
])
->execute();
But i am getting
Cannot convert value to bool : InvalidArgumentException Error message. I have done some google related to this problem but did not find any correct solution.

Invalid argument exceptions are caused because of type mismatch in operations you written in the code.
Check your model class for the type you given and compare it with the code

Related

unable to read messages from messages file in unit test

I want to read the error messages from messages file but I am unable to. What mistake am I making?
The code where I want to read the string from messages file is
Future { Ok(Json.toJson(JsonResultError(messagesApi("error.incorrectBodyType")(langs.availables(0))))) }
The messages file error.incorrectBodyType=Incorrect body type. Body type must be JSON
The messagesApi("error.incorrectBodyType") should return Incorrect body type. Body type must be JSON but it returns error.incorrectBodyType.
If I remove double quotes in messagesApi(error.incorrectBodyType) then the code doesn't compile
Update
I added a couple of debug prints and notice that the keys I am using in MessagesApi are not defined. I don't know why though as I have created them in messages file.
println("langs array"+langs.availables)
println("app.title"+messagesApi.isDefinedAt("app.title")(langs.availables(0)))
println("error"+messagesApi.isDefinedAt("error.incorrectBodyType")(langs.availables(0)))
prints
langs arrayList(Lang(en_GB))
app.titlefalse
errorfalse
Update 2
I might have found the issue but I don't know how to resolve it. Basically, I am running my test case without an instance of the Application. I am mocking messagesApi by calling stubMessagesApi() defined in Helpers.stubControllerComponents, If I run the same code using an Application eg class UserControllerFunctionalSpec extends PlaySpec with OneAppPerSuiteWithComponents then app.title and error are defined. It seems without an instance of Application, MessagesApi is not using the messages file.
I was able to solve the issue by creating a new instance of MessagesApi using DefaultMessagesApi
val messagesApi = new DefaultMessagesApi( //takes map of maps. the first is the language file, the 2nd is the map between message title and description
Map("en" -> //the language file
Map("error.incorrectBodyType" -> "Incorrect body type. Body type must be JSON") //map between message title and description
)
)
val controller = new UserController(mockUserRepository,mockControllerComponents,mockSilhouette,messagesApi,stubLangs())

Syntax for setting/updating register fields in Map CRDT on server

What is the syntax for setting lwwreg register values in CRDT Map on server side in Riak? I tried a code like below which doesn't seem to be valid:
%% Obj is a map object to which we want to add/set a register "uname" with value
%% "ahmed"
riak_kv_crdt:update(Obj,<<"testing">>,{crdt_op,riak_dt_map,
{update,[{assign,<<"uname">>,<<"ahmed">>}]},undefined})
I get an error about the operation being invalid - I looked around in source code for riak_dt_map.erl but still can't figure out correct syntax:
> riak_kv_crdt:update(Obj,<<"testing">>,{crdt_op,riak_dt_map,{update,
[{assign,<<"uname">>,<<"ahmed">>}]},undefined}).
** exception error: no function clause matching
riak_dt_map:apply_ops([{assign,<<"uname">>,<<"ahmed">>}],
{<<"testing">>,1},
{[{<<"testing">>,1}],
.....
Will appreciate pointers on correct syntax.
Figured it out. The correct syntax is below - the key must be accompanied by the type of the field which is riak_dt_lwwreg in this case, and assign operation must be specified for register value - so, the syntax becomes:
riak_kv_crdt:update(Obj,<<"testing">>,{crdt_op,riak_dt_map,{update,
[{update,{<<"uname">>,riak_dt_lwwreg},{assign,<<"ahmed">>}}]},undefined})

HackLang by Facebook is not strict

Good day,
I have problem. I want to simulate some errors in hacklang.
<?hh
namespace Exsys\HHVM;
class HHVMFacade{
private $vector = Vector {1,2,3};
public function echoProduct() : Vector<string>{
return $this->vector;
}
public function test(Vector<string> $vector) : void{
var_dump($vector);
}
}
Function echoProduct() returns Vector of strings. But private property $vector is Vector of integers. When I call echoFunction and returning value use as argument for function test(). I get
object(HH\Vector)#35357 (3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
Why? I am expecting some error because types mismatch.
There's two things at play here:
Generics aren't reified, so the runtime has no information about them. This means the runtime is only checking that you're returning a Vector.
$this->vector itself isn't typed. This means the type checker (hh_client) treats it as a unknown type. Unknown types match against everything, so there's no problem returning an unknown type where a Vector<string> is expected.
This is to allow you to gradually type your code. Whenever a type isn't known, the type checker just assumes that the developer knows what's happening.
The first thing I'd do is change the file from partial mode to strict mode, which simply involves changing from <?hh to <?hh // strict. This causes the type checker to complain about any missing type information (as well as a couple of other things, like no superglobals and you can't call non-Hack code).
This produces the error:
test.hh:6:13,19: Please add a type hint (Naming[2001])
If you then type $vector as Vector<int> (private Vector<int> $vector), hh_client then produces:
test.hh:9:16,28: Invalid return type (Typing[4110])
test.hh:8:44,49: This is a string
test.hh:6:20,22: It is incompatible with an int
test.hh:8:44,49: Considering that this type argument is invariant with respect to Vector
Which is the error you expected. You can also get this error simply by adding the type to $vector, without switching to strict mode, though I prefer to write my Hack in the strongest mode that the code supports.
With more recent versions of HHVM, the type checker is called whenever Hack code is run (there's an INI flag to turn this off), so causing the type mismatch will also cause execution of the code to fail.

Realm on iOS throws "Invalid value '301' for property'code'" where 'code' is of type Int

code is an integer, so it's declared as an Int in my subclass.swift file. The subclass is in the same format as the JSON, to enable saving the JSON directly to Realm.
I get this JSON:
...
"code": 301
...
And this is how I'm saving it:
realm.create(Student.self, value: jsonStudent, update: true)
But Realm throws this:
failed: caught "RLMException", "Invalid value '301' for property 'code'"
At first I thought the '301' might be getting parsed as a string, but that was not the case, calling 'dynamicType' on it in the debugger returns NSCFNumber, which is expected.
What's wrong?
NSJSONSerialization will convert {"code": 301} to an NSNumber of type q, which is integer. So the fact that you're getting an invalid property implies that the code property on your Realm model is of a different type (maybe Float or Double)?
Could you share your model definition here?
If your code property is actually Int or a variation thereof (Int32, Int64, etc.), this would imply there's a bug in Realm and I'd recommend that you open an issue at https://github.com/realm/realm-cocoa/issues.

getting error updating the sqlite

I am doing the project and I am structed in database path. I am using the sqlite database for storing. In this my problems is when I updating the table it showing the error. For database part I am using prewritten classes. I am calling that class method whenever I need. See below you can understand.
This below code is working fine
[DataCachingHelper updateTable:#"sendertable" data:dic3 where:#"MESSAGE_ID='1234'"];
but when I am sending the object to the "where", It showing some error.
[DataCachingHelper updateTable:#"sendertable" data:dic3 where:#"MESSAGE_ID=%#",#"hai"];
i am getting the error:
"too many arguments to methods call expected 3,have 4".
here MESSAGE_ID is VARCHAR TYPE
The issue is clear here. You can not pass string format because compiler compiles parameter before converting into string format. From your method declaration allowed parameters must be 3.
So compiler detect 4 parameter as you pass string with format.
Also in sqlite database for VARCHAR type field use double quotes for field values.
So your string should be like this:
NSString *whereClauseString = [NSString stringWithFormat:#"MESSAGE_ID = \"%#\"",#"hai"];
Or if value is pre known simply create string like this:
NSString *whereClauseString = #"MESSAGE_ID = \"hai\"";
And then use this string as third parameter for updateTable method:
[DataCachingHelper updateTable:#"sendertable" data:dic3 where:whereClauseString];
make this in two step.
NSString *strWhere=[NSString stringWithFormat:#"MESSAGE_ID='%#'",#"hai"];
[DataCachingHelper updateTable:#"sendertable" data:dic3 where:strWhere];

Resources