Uploaded image for project: 'MariaDB Connector/node.js'
  1. MariaDB Connector/node.js
  2. CONJS-193

Wrong error returned "Cannot read properties of undefined… … (reading 'charset')" when error during handshake

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.0
    • Fix Version/s: 3.0.1
    • Component/s: other
    • Labels:
      None
    • Environment:
      MariaDB 10.2.7

      Description

      The following code throws an exception with MariaDB 10.2 whereas with 10.6 it just works.

      [
        { val: 1n },
        meta: [
          ColumnDef {
            _stringParser: [StringParser],
            collation: [Collation],
            columnLength: 1,
            columnType: 8,
            flags: 129,
            scale: 0,
            type: 'BIGINT'
          }
        ]
      ]
      undefined
      /home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/io/packet-output-stream.js:48
          this.encoding = collation.charset;
                                    ^
       
      TypeError: Cannot read properties of undefined (reading 'charset')
          at PacketOutputStream.changeEncoding (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/io/packet-output-stream.js:48:31)
          at EventEmitter.emit (node:events:532:35)
          at Connection.<anonymous> (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/connection.js:595:21)
          at Object.onceWrapper (node:events:640:26)
          at Handshake.emit (node:events:520:28)
          at Handshake.throwError (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/cmd/command.js:90:10)
          at Handshake.parseHandshakeInit (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/cmd/handshake/handshake.js:54:19)
          at PacketInputStream.receivePacketBasic (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/io/packet-input-stream.js:76:9)
          at PacketInputStream.onData (/home/markusjm/sqltest/nodejs/node_modules/mariadb/lib/io/packet-input-stream.js:139:20)
          at Socket.emit (node:events:520:28)
      

      const mariadb = require("mariadb")
      const pool = mariadb.createPool({
          host: '127.0.0.1',
          port: 3000,
          user:'maxuser',
          password: 'maxpwd',
          connectionLimit: 100
      });
      async function asyncFunction() {
          let conn;
          try {
              conn = await pool.getConnection();
              const rows = await conn.query("SELECT 1 as val");
              console.log(rows); //[ {val: 1}, meta: ... ]                                                                                                                                                                                                                                      
              const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
              console.log(res); // { affectedRows: 1, insertId: 1, warningStatus: 0 }                                                                                                                                                                                                           
          } catch (err) {
              throw err;
          } finally {
              if (conn) return conn.end();
          }
      }
      asyncFunction().then(console.log, console.log)
      

        Attachments

          Activity

            People

            Assignee:
            diego dupin Diego Dupin
            Reporter:
            markus makela markus makela
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.