Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNKNOWN_CODE_PLEASE_REPORT - Code 4025 #1982

Open
apopescu-im opened this issue Apr 2, 2018 · 8 comments
Open

UNKNOWN_CODE_PLEASE_REPORT - Code 4025 #1982

apopescu-im opened this issue Apr 2, 2018 · 8 comments
Assignees
Labels

Comments

@apopescu-im
Copy link

Got this from a failing constraint:

--> ComQueryPacket
ComQueryPacket {
  command: 3,
  sql: 'insert into `roles` (`bu_id`, `comment`, `community_id`, `is_admin`, `is_master`, `user_id`) values (1, \'\', 1, false, false, 11)' }

<-- ErrorPacket
ErrorPacket {
  fieldCount: 255,
  errno: 4025,
  sqlStateMarker: '#',
  sqlState: '23000',
  message: 'CONSTRAINT `exactly_one_fk_id` failed for `insights-system`.`roles`' }

The failing constraint was defined as:

ALTER TABLE roles ADD CONSTRAINT exactly_one_fk_id CHECK (community_id IS NULL XOR bu_id IS NULL)

Server version is MariaDB 10.2.12

@kai-koch
Copy link
Collaborator

kai-koch commented Apr 2, 2018

This is the correct behaviour for the defined CONSTRAINT and the given example.

Both community_id AND bu_id have a value, so the the XOR-Constraint is not meet.
XOR returns false and an error is thrown, which should be caught and dealt with in your code.

XOR-truth-table

Input Output
0, 0 false
0 , 1 true
1 , 0 true
1 , 1 false

check https://en.wikipedia.org/wiki/Exclusive_or for details on the logic of how XOR works.

Closed: no mysqljs error

@kai-koch kai-koch closed this as completed Apr 2, 2018
@apopescu-im
Copy link
Author

@kai-koch Yes, I'm aware how XOR works. The given query is intended to fail, as we were testing that the constraint is in place and properly set up. The reason I posted this is the fact that the error is called "UNKNOWN_CODE_PLEASE_REPORT" so it sounds like a code that needs to have a name defined for it.

Here's the error info:

Error handler { Error: UNKNOWN_CODE_PLEASE_REPORT: CONSTRAINT `exactly_one_fk_id` failed for `insights-system`.`roles`
    at Query.Sequence._packetToError (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
    at Query.ErrorPacket (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
    at Protocol._parsePacket (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/proj/r2/insights/admin-api/node_modules/mysql/lib/Connection.js:103:28)
    at Socket.emit (events.js:159:13)
    at addChunk (_stream_readable.js:265:12)
    at readableAddChunk (_stream_readable.js:252:11)
    at Socket.Readable.push (_stream_readable.js:209:10)
    at TCP.onread (net.js:598:20)
    --------------------
    at Protocol._enqueue (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Connection.query (/proj/r2/insights/admin-api/node_modules/mysql/lib/Connection.js:208:25)
    at /proj/r2/insights/admin-api/node_modules/knex/lib/dialects/mysql/index.js:161:18
    at Promise._execute (/proj/r2/insights/admin-api/node_modules/bluebird/js/release/debuggability.js:303:9)
    at Promise._resolveFromExecutor (/proj/r2/insights/admin-api/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/proj/r2/insights/admin-api/node_modules/bluebird/js/release/promise.js:79:10)
    at Client_MySQL._query (/proj/r2/insights/admin-api/node_modules/knex/lib/dialects/mysql/index.js:155:12)
    at Client_MySQL.query (/proj/r2/insights/admin-api/node_modules/knex/lib/client.js:199:17)
    at /proj/r2/insights/admin-api/node_modules/knex/lib/transaction.js:274:21
    at tryCatcher (/proj/r2/insights/admin-api/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.attempt.Promise.try (/proj/r2/insights/admin-api/node_modules/bluebird/js/release/method.js:39:29)
    at Client_MySQL.trxClient.query (/proj/r2/insights/admin-api/node_modules/knex/lib/transaction.js:271:34)
    at Runner.<anonymous> (/proj/r2/insights/admin-api/node_modules/knex/lib/runner.js:149:36)
    at Runner.tryCatcher (/proj/r2/insights/admin-api/node_modules/bluebird/js/release/util.js:16:23)
    at Runner.query (/proj/r2/insights/admin-api/node_modules/bluebird/js/release/method.js:15:34)
    at /proj/r2/insights/admin-api/node_modules/knex/lib/runner.js:61:21

@kai-koch
Copy link
Collaborator

kai-koch commented Apr 3, 2018

Thanks, for providing more information.

Is the error-trace from the same script as the mysqljs error in the initial posting?
In the first post it seems the error is recognized as Constraint failure by mysqljs and could be caught as it is expected by you.
Which version of mysqljs you are running?

@apopescu-im
Copy link
Author

Yes, everything I pasted comes from the same run of the program. Version of mysqljs is 2.15.0. I'm not sure exactly where the output I posted in the original post fires from, though I assume it's a side effect of creating a Knex connection with debug: true.

To give you a bit of a bigger picture, our code uses Objection models on top of a Knex connection pool which I presume relies on mysqljs to interface to the server. That output and the stack were both generated when trying to insert an Objection entity that (purposefully) failed the constraint.

@kai-koch
Copy link
Collaborator

kai-koch commented Apr 3, 2018

Which client do you use in the knex-config / initialization?
mysql, mysql2 or mariasql?
MariaDB should be fully compatible with MySQL, but I do not know, if it is completely up to date.

I have no experience with knex, but maybe the file '[...]/admin-api/node_modules/knex/lib/dialects/mysql/index.js' is not for the same version as the module '[...]/admin-api/node_modules/mysql/'

Can you provide code that runs without knex and that reproduces the error?

@apopescu-im
Copy link
Author

The code below reproduces this with just mysql. I ran it in the same project as the original above, so same version, etc.

I took a (very brief) look through mysqljs and to me it seems that Query extends Sequence and calls its _packetToError which tries to map packet.errno to an error defined in Errors. However, errors.js only lists errors up to 3198, so this packet's 4025 is unmapped. It may be as simple as needing to add the two lines to map that value, though I don't know what other impact this could have, or what the expected name would be for this.

const mysql = require("mysql");

const conn = mysql.createConnection({
  host     : "***",
  port: ***,
  user     : "***",
  password : "***",
  database: "***",
  debug: true
});

conn.connect((err) => {
  if (err)
    throw err;

  conn.query(
    {
      sql: "INSERT INTO roles (bu_id, community_id, user_id) VALUES (3, 3, 1)"
    },
    (err, results, fields) => {
      if (err)
        throw err;

      console.log(results);
      console.log(fields);
    }
  );
});

Output (starting after the auth success packets):

--> ComQueryPacket
ComQueryPacket {
  command: 3,
  sql: 'INSERT INTO roles (bu_id, community_id, user_id) VALUES (3, 3, 1)' }

<-- ErrorPacket
ErrorPacket {
  fieldCount: 255,
  errno: 4025,
  sqlStateMarker: '#',
  sqlState: '23000',
  message: 'CONSTRAINT `exactly_one_fk_id` failed for `insights-system`.`roles`' }
/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Parser.js:80
        throw err; // Rethrow non-MySQL errors
        ^

Error: UNKNOWN_CODE_PLEASE_REPORT: CONSTRAINT `exactly_one_fk_id` failed for `insights-system`.`roles`
    at Query.Sequence._packetToError (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
    at Query.ErrorPacket (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
    at Protocol._parsePacket (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/proj/r2/insights/admin-api/node_modules/mysql/lib/Connection.js:103:28)
    at Socket.emit (events.js:159:13)
    at addChunk (_stream_readable.js:265:12)
    at readableAddChunk (_stream_readable.js:252:11)
    at Socket.Readable.push (_stream_readable.js:209:10)
    --------------------
    at Protocol._enqueue (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Connection.query (/proj/r2/insights/admin-api/node_modules/mysql/lib/Connection.js:208:25)
    at Handshake.conn.connect [as _callback] (/proj/r2/insights/admin-api/test-mysql.js:16:8)
    at Handshake.Sequence.end (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
    at Handshake.Sequence.OkPacket (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/sequences/Sequence.js:97:8)
    at Protocol._parsePacket (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/proj/r2/insights/admin-api/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/proj/r2/insights/admin-api/node_modules/mysql/lib/Connection.js:103:28)
    at Socket.emit (events.js:159:13)

Process finished with exit code 1

@kai-koch
Copy link
Collaborator

kai-koch commented Apr 4, 2018

Yes, that is also my assumption.
But @dougwilson should have a look first and decide if it is just adding to lines to the error.js and we are good. Since I am not up-to-date on the error-messages and numbers of the different version of MySQL and mariaDB.

@dougwilson
Copy link
Member

Hi sorry for my absence. Yes, the constant for 4025 is not in our file. You can also see from the message at the top of the file not to modify it by hand :) The file is populated using the tool shown in the comments at the top of the time from MySQL source files.

Looking into this, it seems like MariaDB has a bunch of their own, custom error in the 4xxx range. Since the error constants are only build from the MySQL source code, that would explain why this MariaDB-specific error is not there.

The solution here is to update the tool to also scrape the error constants from the MariaDB source code in addition to just the MySQL source code. I'm working on that 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants