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

Errors are inconsistent and don't match those thrown by mysql.js #118

Open
ChrsWoo opened this issue Sep 3, 2021 · 1 comment
Open

Errors are inconsistent and don't match those thrown by mysql.js #118

ChrsWoo opened this issue Sep 3, 2021 · 1 comment

Comments

@ChrsWoo
Copy link

ChrsWoo commented Sep 3, 2021

Good afternoon, I hope this isn't a duplicate.

While attempting to debug an error, we noticed that the errors being thrown by the query() were not providing us with the information we expected.

To illustrate, I've produced an ER_ACCESS_DENIED_ERROR error locally with both serverless-mysql and mysql.js.

// ++ mysql.js ++
const connection = mysql.createConnection(databaseDetails);
connection.query("SELECT 1", function (error, results, fields) {
    if (error) {
        console.log(error);
    }
});

Outputs:

console.log
    Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: YES)
        // ++ Stack trace omitted++
    {
      code: 'ER_ACCESS_DENIED_ERROR',
      errno: 1045,
      sqlMessage: "Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: YES)",
      sqlState: '28000',
      fatal: true
    }

By contrast;

// ++ serverless-mysql ++
const connection = serverlessMysql({
    library: mysql,
    config: databaseDetails,
});

try {
    await connection.query("SELECT 1");
    await this.connection.end();
} catch (error) {
    console.log(error);
}

Outputs;

console.log
    Error: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'xxx.xxx.xxx.xxx' (using password: YES)
        // ++ Stack trace omitted ++

You can see the original Error thrown by mysql.js appears to have been stringified, and then re-thrown within another Error by serverless-mysql, losing the helpful MysqlError object that can be interrogated programmatically.

Is this a bug? How can we get the code, errno, etc. out of the error thrown by serverless-mysql?

@ChrsWoo
Copy link
Author

ChrsWoo commented Sep 3, 2021

I forgot to mention an important factor in this.

I can see in our application logs that some errors thrown by serverless-mysql do seem to include the whole MysqlError object - specifically when the error code in question is ECONNRESET however I don't know how to reproduce that locally.

@ChrsWoo ChrsWoo changed the title Errors are inconsistent and don't match those thrown my mysql.js Errors are inconsistent and don't match those thrown by mysql.js Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant