project-error / npwd

NPWD is a FiveM phone resource written entirely in TypeScript and React.
https://projecterror.dev
Other
336 stars 277 forks source link

Bug: new db string parser failing #1094

Closed ChatDisabled closed 7 months ago

ChatDisabled commented 8 months ago

Development Issue

Yes

Phone Version

1.8.3

Issue Description

NPWD will fail executing (SHOW TABLES WHERE `Tables_in_@localhost/QboxProject_49547B?charset=utf8mb4`LIKE ? ["players"]) as Tables_in_@localhost/QboxProject_49547B?charset=utf8mb4 is obviously not a valid column. This error doesn't occur when using 1.8.2.

Issue Reproduction

Use https://raw.githubusercontent.com/Qbox-project/txAdminRecipe/main/qbox.yaml as a recipe deployer

Evidence

image

jayz666 commented 8 months ago

The error message you provided appears to be a database query issue, and it is likely related to the code that interacts with the database in your script. To fix the issue, you need to correct the SQL query syntax, check your database connection, and handle promise rejections. Here are the steps you can take to address the problem:

SQL Query Syntax Issue: Review and correct the SQL query in your code. The error message suggests a syntax issue in the SQL query. Make sure your query follows the correct syntax for listing tables in your database. The corrected query should look something like this:

sql Copy code SHOW TABLES LIKE 'users'; If you're using a specific database library or ORM, ensure that you're using the library's methods correctly for executing this query.

Database Connection Configuration: Verify that your database connection settings are correctly configured in your script. Double-check the database URL, username, password, and other connection parameters to ensure they match your database setup. If you're using a specific library to manage the database connection, ensure that the configuration is accurate.

Promise Handling: The error message mentions an unhandled promise rejection. Ensure that your script correctly handles promises and asynchronous operations. You should use .then() and .catch() or async/await to handle promises. Here's an example of how you might handle a promise correctly:

javascript Copy code someAsyncFunction() .then(result => { // Handle the result }) .catch(error => { // Handle the error }); Make sure that any promises in your script are properly resolved or rejected and that you handle errors appropriately.

Debugging: If you're still facing issues after making these changes, consider adding debugging statements or logging to your code to help pinpoint the exact location and cause of the error. This can be helpful in diagnosing and fixing the problem.

Remember to review the specific code in your script that triggers the database query and handles promises. Without access to the full script and context, it's challenging to provide a more precise solution, but the steps above should help you identify and resolve the issue. If you encounter specific errors or issues in your code, providing more details can help in offering more targeted assistance.

ChatDisabled commented 8 months ago

That's cool and all but how is this any of my problem when this issue started after 1.8.3. Which more than likely comes down to https://github.com/project-error/npwd/pull/1086. It states that it supports "mysql://root:12345@localhost:3306/npwd but it clearly doesn't which results in the error above. Even though any and all recipe deployers will end up like "mysql://root@localhost/QboxProject_49547B?charset=utf8mb4". So is it because we set a charset? Is it because we don't use a password? Who knows because I for one can't read nor write TS so it might as well be Chinese for me.

itschip commented 8 months ago

yeah, seems to be the charset that's fucking it up

ChatDisabled commented 8 months ago

Can confirm that this is the result of the new update expecting a required password being set for the user. Specifying the db port has no effect nor the charsetting. "mysql://test@localhost/QboxProject_49547B?charset=utf8mb4" image

"mysql://test:password@localhost/QboxProject_49547B?charset=utf8mb4" image

itschip commented 8 months ago

What if you just run "mysql://test:@localhost/QboxProject_49547B?charset=utf8mb4"

ChatDisabled commented 8 months ago

Same error, it expects a value to be there before the @

lukealford commented 8 months ago

I'll investigate it this weekend. I honestly never tested no password, because well I've never in my life had no password/user on my DB instance, even when using ssh keys I still would have a password. 🤣

itschip commented 8 months ago

@lukealford welcome to FiveM :P This is just something we have to fix :))

ChatDisabled commented 8 months ago

Most server owners don't even know what ssh keys are. 99% of the environments are solely locally and managed by one person so there would never be any advantage to using passwords let alone user management with specific access. The 1% that even wants to access their db outside their local environment are smart enough that this has to be done in a secure way. Which indeed comes down to welcome to FiveM. Professionalism bar is very low here.

izmystic commented 7 months ago

The error message you provided appears to be a database query issue, and it is likely related to the code that interacts with the database in your script. To fix the issue, you need to correct the SQL query syntax, check your database connection, and handle promise rejections. Here are the steps you can take to address the problem:

SQL Query Syntax Issue: Review and correct the SQL query in your code. The error message suggests a syntax issue in the SQL query. Make sure your query follows the correct syntax for listing tables in your database. The corrected query should look something like this:

sql Copy code SHOW TABLES LIKE 'users'; If you're using a specific database library or ORM, ensure that you're using the library's methods correctly for executing this query.

Database Connection Configuration: Verify that your database connection settings are correctly configured in your script. Double-check the database URL, username, password, and other connection parameters to ensure they match your database setup. If you're using a specific library to manage the database connection, ensure that the configuration is accurate.

Promise Handling: The error message mentions an unhandled promise rejection. Ensure that your script correctly handles promises and asynchronous operations. You should use .then() and .catch() or async/await to handle promises. Here's an example of how you might handle a promise correctly:

javascript Copy code someAsyncFunction() .then(result => { // Handle the result }) .catch(error => { // Handle the error }); Make sure that any promises in your script are properly resolved or rejected and that you handle errors appropriately.

Debugging: If you're still facing issues after making these changes, consider adding debugging statements or logging to your code to help pinpoint the exact location and cause of the error. This can be helpful in diagnosing and fixing the problem.

Remember to review the specific code in your script that triggers the database query and handles promises. Without access to the full script and context, it's challenging to provide a more precise solution, but the steps above should help you identify and resolve the issue. If you encounter specific errors or issues in your code, providing more details can help in offering more targeted assistance.

🤓

lukealford commented 7 months ago

So I've found the problem,

  1. It treated it as a special regex case it's not
  2. the driver HATES empty strings in the options

I'll have a PR up shortly to fix no password cases, I tested


mysql://test@localhost/testdb?charset=utf8mb4 
mysql://localhost/testdb?user=test&charset=utf8mb4
mysql://localhost/testdb?username=test&charset=utf8mb4