Sending a `create` RPC message to SurrealDB returns a "There was a problem with the database: The table does not exist" error - surrealdb

I'm debugging some tests for the .NET SurrealDB library. I can open connections to the database just fine but when I send a create RPC message to the db (docker container) it returns an error that reads "There was a problem with the database: The table does not exist"
TRACE tungstenite::protocol Received message {"id":"02B70C1AFE5D","async":true,"method":"create","params":["users",{"username":"john","password":"test123"}]}
...
16 13:46:45] DEBUG surrealdb::dbs Executing: CREATE $what CONTENT $data RETURN AFTER
surreal_1 | [2022-09-16 13:46:45] TRACE surrealdb::dbs Iterating: CREATE $what CONTENT $data RETURN AFTER
code: -32000, message: "There was a problem with the database: The table does not exist"
Any idea why that would happen? The table, of course, doesn't exist since I'm trying to create it. Would there be another reason in the Surreal code that such an error would be returned?

The error message was a red herring. The actual issue was that the client had an error that didn't allow it to sign in correctly so it wasn't authorized to make changes to the database.
Offending code:
// The table doesn't exist
Err(Error::TbNotFound) => match opt.auth.check(Level::Db) {
// We can create the table automatically
true => {
run.add_and_cache_ns(opt.ns(), opt.strict).await?;
run.add_and_cache_db(opt.ns(), opt.db(), opt.strict).await?;
run.add_and_cache_tb(opt.ns(), opt.db(), &rid.tb, opt.strict).await
}
// We can't create the table so error
false => Err(Error::TbNotFound), // Wrong Error Message
},
This has since been fixed and should now return a query permission error if the client is unauthorized.

Related

Laravel sporadic EncryptException "Could not encrypt the data." in EncryptCookies

We have a CentOS LAMP server with PHP5.6.37, openSSL 1.0.2, Laravel 5.4.
Sporadically we receive the following error:
exception 'Illuminate\Contracts\Encryption\EncryptException' with message 'Could not encrypt the data.' in ./Illuminate/Encryption/Encrypter.php:95
Stack trace:
#0 ./Illuminate/Cookie/Middleware/EncryptCookies.php(131): Illuminate\Encryption\Encrypter->encrypt('KoKVTECWZF4A8x7...')
#1 ./Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Cookie\Middleware\EncryptCookies->encrypt(Object(Illuminate\Http\Response))
The problematic code is:
$json = json_encode(compact('iv', 'value', 'mac'));
if (!is_string($json)) {
throw new EncryptException('Could not encrypt the data.');
}
These exceptions happen sporadically, all in the early morning hours (3AM-8AM) , sometimes there are no errors for couple of weeks, then they happen every consecutive day.
ATM we cannot switch to PHP7.
EDIT 1:
I have logged the values, where the program crashes during the night. If I rerun the code, I get normal response without an Exception.
$value = 'a51446732955fcf3bb467fc135741ae7956dc247d562b16157de231b8d792400';
$mac = 'Xdo0mGNCeX4p2AHj4cgbmounu3F2bql05uSmve7DDmUWpmMJ1ysmsSrGPg+57N52FxqszqDU5PBTGMihan7ZZQ==';
echo json_encode(compact('iv', 'value', 'mac'));
1{"iv":"yHUQHrhaXq7T+VikdvXuqQ==","value":"a51446732955fcf3bb467fc135741ae7956dc247d562b16157de231b8d792400","mac":"Xdo0mGNCeX4p2AHj4cgbmounu3F2bql05uSmve7DDmUWpmMJ1ysmsSrGPg+57N52FxqszqDU5PBTGMihan7ZZQ=="}```

The "error_marshaling_enabled" setting seems to be always enabled

When I run this code:
$client->evaluate('
box.session.settings.error_marshaling_enabled = false
box.error{code = 42, reason = "Foobar", type = "MyError"}
');
regardless of the value of error_marshaling_enabled I always get a response with a new (extended) error format:
[
49 => 'Foobar',
82 => [
0 => [
0 => [
0 => 'CustomError',
2 => 3,
1 => 'eval',
3 => 'Foobar',
4 => 0,
5 => 42,
6 => [
'custom_type' => 'MyError',
],
],
],
],
],
Why is that?
Short answer.
error_marshaling_enabled option affects only how error objects are encoded in response body (48, IPROTO_DATA). It does not affect how they are returned as exceptions, in the response header (82, IPROTO_ERROR).
Long answer.
In Tarantool an error object can be returned in 2 ways: as an exception and as an object. For example, this is how to throw an error as exception:
function throw_error()
box.error({code = 1000, reason = "Error message"})
-- Or
error('Some error string')
end
This is how to return it as an object:
function return_error()
return box.error.new({code = 1000, reason = "Error message"})
end
If the function was called remotely, using IPROTO protocol via a connector like netbox, or PHP connector, or any other one, the error return way affects how it is encoded into MessagePack response packet. When the function throws, and the error reaches the top stack frame without being caught, it is encoded as IPROTO_ERROR (82) and IPROTO_ERROR_24 (49).
When the error object is returned as a regular value, not as an exception, it is encoded also as a regular value, inside IPROTO_DATA (48). Just like a string, a number, a tuple, etc.
With encoding as IPROTO_ERROR/IPROTO_ERROR_24 there is no much of a configuration space. Format of these values can't be changed. IPROTO_ERROR is always returned as a MessagePack map, with a stack of errors in it. IPROTO_ERROR_24 is always an error message. The IPROTO_ERROR_24 field is kept for compatibility with connectors to Tarantool versions < 2.4.1.
With encoding as a part of IPROTO_DATA you can choose serialization way using error_marshaling_enabled option. When it is true, errors are encoded as MessagePack extension type MP_EXT, and contain the whole error stack, encoded exactly like IPROTO_ERROR value. When the option is false (default behaviour in 2.4.1), the error is encoded as a string, MP_STR, which is the error's message. If there is a stack of errors, only the newest error is encoded.
error_marshaling_enabled option exists for backward compatibility, in case your application on Tarantool wants to be compatible with old connectors, which don't support MP_EXT encoded errors.
In Tarantool < 2.4.1 errors were encoded into result MessagePack as a string with error message, and error stacks didn't exist at all. So when the new format and the error stacks feature were introduced, making the new format default would be a too radical change breaking the old connectors.
Consider these examples of how error marshaling affects results. I use Tarantool 2.4.1 console here, and built-in netbox connector. The code below can be copy pasted into the console.
First instance:
box.cfg{listen = 3313}
box.schema.user.grant('guest', 'super')
function throw_error()
box.error({code = 1000, reason = "Error message"})
end
function return_error()
return box.error.new({code = 1000, reason = "Error message"})
end
Second instance:
netbox = require('net.box')
c = netbox.connect(3313)
Now I try to call the function on the second instance:
tarantool> c:call('throw_error')
---
- error: Error message
...
The c:call('throw_error') threw an exception. If I catch it using pcall() Lua function, I will see the error object.
tarantool> ok, err = pcall(c.call, c, 'throw_error')
tarantool> err:unpack()
---
- code: 1000
base_type: ClientError
type: ClientError
message: Error message
trace:
- file: '[string "function throw_error()..."]'
line: 2
...
As you can see, I didn't set error_marshaling_enabled, but got the full error. Now I will call the other function, without exceptions. But the error object won't be full.
tarantool> err = c:call('return_error')
tarantool> err
---
- Error message
...
tarantool> err:unpack()
---
- error: '[string "return err:unpack()"]:1: attempt to call method ''unpack'' (a nil
value)'
...
The error was returned as a mere string, error message. Not as an error object. Now I will turn on the marshaling:
tarantool> c:eval('box.session.settings.error_marshaling_enabled = true')
---
...
tarantool> err = c:call('return_error')
---
...
tarantool> err:unpack()
---
- code: 1000
base_type: ClientError
type: ClientError
message: Error message
trace:
- file: '[C]'
line: 4294967295
...
Now the same function returned the error in the new format, more featured.
On the summary: error_marshaling_enabled affects only returned errors. Not thrown errors.

XML Parsing Error : AJAX Chat

I am just trying to plant AJAX Chat for my website users. I have successfully completed the installation process with database configuration. But when I am trying to brows the domain.com/ajaxchat/index.php its returning this error given below:
XML Parsing Error: junk after document element Location: http://futurenext.esy.es/inc/chat/ Line Number 2, Column 1:
I think that the problem is in AJAXChatTemplate.php , and here the code is:
function getContent() {
if(!$this->_content) {
$this->_content = AJAXChatFileSystem::getFileContents($this->_templateFile);
}
return $this->_content;
And the error message is like:
" Non-static method AJAXChatFileSystem::getFileContents() should not be called statically, assuming $this from incompatible context in line 37"
Now please any one can help me to fix the problem. What is the problem here I can't really understand. Thanks.

DBD::Oracle::st execute failed: system generated message

For oracle system generated Software Error messages during prepare/execute query invalid. displays complete query to user on a webpage. want to replace system generated message with user common message.
example:
Software error:
DBD::Oracle::st execute failed: ORA-01722: invalid number (DBD ERROR: error possibly near <> indicator at char 136 in 'SELECT EQUIPID, EQUIPSHORTNAME, MAXLIMITEDDAYS, STATUS, EQUIPNAME FROM LAB_EQUIPMENT_DETAILS WHERE CATEGORYID = '3' AND SUBCATEGORYID = <>' ' AND STATUS != 'DELETE'') [for Statement "SELECT EQUIPID, EQUIPSHORTNAME, MAXLIMITEDDAYS, STATUS, EQUIPNAME FROM LAB_EQUIPMENT_DETAILS WHERE CATEGORYID = '3' AND SUBCATEGORYID = '****' AND STATUS != 'DELETE'"] at /proj/aa/bb/Source/Global_Routines_general_apps.pm line 126.
For help, please send mail to the webmaster ([...]), giving this error message and the time and date of the error.
Can anyone please help me in doing this.
Thanks in advance.
Simply wrap your execute statement in an eval block and catch the error.
eval {
$sth->execute();
...
};
if ( $# ) {
# log the full error message
write_log( $sth->errstr );
# and re-throw the common message
die 'HEY!!!! Something is messed up here!';
}

How to get HTTP StatusCodes in ember-data

When I invoke
App.store.createRecord(App.User, { name: this.get("name") });
App.store.commit();
how do I know if its successful and how to wait for the asyn message?
Very limited error handling was recently added to DS.RESTAdapter in ember-data master.
When creating or updating records (with bulk commit disabled) and a status code between 400 and 599 is returned, the following will happen:
A 422 Unprocessable Entity will transition the record to the "invalid" state and will add any errors returned from the server to the record's errors property.
The adapter assumes the server will respond with JSON in the following format:
{
errors: {
name: ["can't be blank"],
password: ["must be at least 8 characters", "must contain a number"]
{
}
(The error messages themselves could be arrays of strings or just strings. ember-data doesn't currently care which.)
To detect this state:
record.get('isValid') === false
All other status codes will transition the record to the "error" state.
To detect this state, use:
record.get('isError') === true
More cases may eventually be handled by ember-data out of the box, but for the moment if you need something specific, you'll have to extend DS.RESTAdapter, customizing its didError function to add it in yourself.

Resources