project-error / npwd

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

Bug: Unhandled promise failure: TypeError: Cannot read properties of null (reading '2') #738

Closed LifeGoal closed 1 year ago

LifeGoal commented 2 years ago

Development Issue

Unsure

Phone Version

1.2.96

Issue Description

When the resource has started, an error pops up in the server-sided console. I'm unsure if it does anything but I feel like you should know that there is such an error even though it might not be an issue afterall.

I've tested the phone after the error pops out and I can't find any faults what so ever. I'm on a Linux server. Only comes when the server starts, so nothing else other than that.

Here is the full error:

[script:npwd] Error: Unhandled promise failure: TypeError: Cannot read properties of null (reading '2')
[script:npwd]     at parseUri (@npwd/resources/dist/server/server.js:34430:39)
[script:npwd]     at _BootDb.<anonymous> (@npwd/resources/dist/server/server.js:34511:31)
[script:npwd]     at Generator.next (<anonymous>)
[script:npwd]     at @npwd/resources/dist/server/server.js:61:61
[script:npwd]     at new Promise (<anonymous>)
[script:npwd]     at __async (@npwd/resources/dist/server/server.js:45:10)
[script:npwd]     at _BootDb.doesPlayerTableExist (@npwd/resources/dist/server/server.js:34510:16)
[script:npwd]     at _BootService.<anonymous> (@npwd/resources/dist/server/server.js:34585:58)
[script:npwd]     at Generator.next (<anonymous>)
[script:npwd]     at @npwd/resources/dist/server/server.js:61:61

Haven't changed anything really other than just set it up by your documentation. No changes to the code.

Issue Reproduction

  1. Start the server
  2. Bang, there it is instantly

(Only comes when server starts)

Evidence

Picture of error (Link to Imgur)

LiamDormon commented 2 years ago

What does your config look like?

LifeGoal commented 2 years ago

I've implemented QBCore to the phone now so it looks like this. Still has the same error.

  "PhoneAsItem": {
    "enabled": true,
    "exportResource": "qb-npwd",
    "exportFunction": "HasPhone"
  },
  "general": {
    "useResourceIntegration": true,
    "toggleKey": "f2",
    "toggleCommand": "phone",
    "defaultLanguage": "en"
  },
  "profanityFilter": {
    "enabled": false,
    "badWords": ["esx"]
  },
  "database": {
    "useIdentifierPrefix": false,
    "playerTable": "players",
    "identifierColumn": "citizenid",
    "identifierType": "license",
    "profileQueries": true,
    "phoneNumberColumn": "phone_number"
  },
  "debug": {
    "level": "error",
    "enabled": true,
    "sentryEnabled": true
  }
}
itschip commented 2 years ago

@LifeGoal still an issue? Have you tried setting useIdentifierPrefix to true?

xxstreetstylexx commented 2 years ago

Hey all,

same issue here. Take a look into the Docs and figure out that set mysql_connection_string in docs is in other format than in fivem config.

try to transform the fivem connection string to the expected one.

fivem expect server=xxx;database=xxx; (...) like on docs: https://www.connectionstrings.com/mysql/

npwd seems to be expect it in form mysql://user:pass@server/db? (...)

if i change it to mysql:// the server wont be able to connect but it seems that nwpd works (no error in log relatet to that) and this error disappears. oxmysql dont can connect even the password is uri encoded.

itschip commented 2 years ago

We should support both. I'll look into it, but good to know that url connection strings works, somwhat. Can you show me the connection string you tried that caused the error, @xxstreetstylexx ?

xxstreetstylexx commented 2 years ago

@itschip

This one dont Work (EDIT for NPWD but for OXMySQL): set mysql_connection_string "server=127.0.0.01;database=fivem;userid=root;password=PASSWORDHIDDEN"

This one dont give any type of issue for NPWD but for oxmysql set mysql_connection_string "mysql://root@localhost/fivem?charset=utf8mb4&password=PASSWORDHIDDEN-URIENCODED"

[ script:oxmysql] Error: Unable to establish a connection to the database! [ script:oxmysql] [Error: Access denied for user 'root'@'localhost']

This one also dont work: set mysql_connection_string "mysql://root:PASSWORDHIDDEN-URIENCODED@localhost/fivem?charset=utf8mb4"

xxstreetstylexx commented 2 years ago

@itschip sorry now the full and not confusing results. :)

server.cfg set mysql_connection_string "mysql://root@localhost/fivem?charset=utf8mb4&password=[uri-encoded-password]"

results in:

sv_npwd.log

{"level":"debug","message":"Beginning database schema validation","module":"boot","timestamp":"2022-05-09T13:57:13.643Z"}
{"level":"info","message":"Successfully started","timestamp":"2022-05-09T13:57:13.657Z"}
{"level":"info","message":"Executed query (SHOW TABLES WHERE `Tables_in_fivem`LIKE ? [\"users\"]) in 212.671645ms'","module":"DBInterface","timestamp":"2022-05-09T13:57:13.857Z"}
{"level":"info","message":"Executed query (SHOW COLUMNS IN users []) in 15.35263ms'","module":"DBInterface","timestamp":"2022-05-09T13:57:13.874Z"}
{"level":"debug","message":"Database schema successfully validated","module":"boot","timestamp":"2022-05-09T13:57:13.874Z"}
{"level":"debug","message":"Checking for missing framework dependencies","module":"boot","timestamp":"2022-05-09T13:57:13.875Z"}
{"level":"debug","message":"No missing dependencies were detected","module":"boot","timestamp":"2022-05-09T13:57:13.877Z"}

server.log

[      script:oxmysql] Error: Unable to establish a connection to the database!
[      script:oxmysql] [Error: Access denied for user 'root'@'localhost']

Result: Phone seems to be working with MySql but OxMySQL cant connect

server.cfg set mysql_connection_string "mysql://root:[uri-encoded-password]@localhost/fivem?charset=utf8mb4"

results in:

sv_npwd.log {"level":"error","message":"Error executing (SHOW TABLES WHERETables_in_fivemLIKE ? [\"users\"]) with error message Access denied for user 'root'@'localhost'","module":"DBInterface","timestamp":"2022-05-09T14:01:22.483Z"}

server.log

[         script:npwd] [NPWD] [DBInterface] [error]: Error executing (SHOW TABLES WHERE `Tables_in_fivem`LIKE ? ["users"]) with error message Access denied for user 'root'@'localhost'
[         script:npwd] Error: Unhandled promise failure: TypeError: (intermediate value) is not iterable
[         script:npwd]     at _BootDb.<anonymous> (@npwd/resources/dist/server/server.js:34514:29)
[         script:npwd]     at Generator.next (<anonymous>)
[         script:npwd]     at fulfilled (@npwd/resources/dist/server/server.js:48:24)
[         script:npwd]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[      script:oxmysql] Error: Unable to establish a connection to the database!
[      script:oxmysql] [Error: Access denied for user 'root'@'localhost']

Result: Nothing is working.

server.cfg

FiveM MySQL Connection string

set mysql_connection_string "server=127.0.0.01;database=fivem;userid=root;password=[password]"

results in:

sv_npwd.log

ends at {"level":"info","message":"Successfully started","timestamp":"2022-05-09T14:03:37.042Z"}

server.log

[         script:npwd] Error: Unhandled promise failure: TypeError: Cannot read properties of null (reading '2')
[         script:npwd]     at parseUri (@npwd/resources/dist/server/server.js:34430:39)
[         script:npwd]     at _BootDb.<anonymous> (@npwd/resources/dist/server/server.js:34511:31)
[         script:npwd]     at Generator.next (<anonymous>)
[         script:npwd]     at @npwd/resources/dist/server/server.js:61:61
[         script:npwd]     at new Promise (<anonymous>)
[         script:npwd]     at __async (@npwd/resources/dist/server/server.js:45:10)
[         script:npwd]     at _BootDb.doesPlayerTableExist (@npwd/resources/dist/server/server.js:34510:16)
[         script:npwd]     at _BootService.<anonymous> (@npwd/resources/dist/server/server.js:34585:58)
[         script:npwd]     at Generator.next (<anonymous>)
[         script:npwd]     at @npwd/resources/dist/server/server.js:61:61

Result: OxMySQL can connect but npwd dont.

if i take a look at the jsat line 34430 i see that it trys to match with an uri (Regex on #34427). This dont even work with fivem i guess. For my understanding the if-statement on this function seems to be not work as expected.

Regards, style

EDIT: \dist\server\server.js #34430 fails and abort whole execution.

if you comment out #34429 to 34441 then the script works.

splitMatchGroups[2] is null on the regular connection string and js seems to dont like it.

itschip commented 2 years ago

@LifeGoal are you able to reproduce this in 1.5.0?

FlavioMoretti commented 2 years ago

@itschip I can reproduce this issue when using an # in the password it won't work. If I remove the # from the password in the db and in the connection string, everything works fine.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

thefalconrain commented 1 year ago

I ran into this exact error and was able to resolve it.

Solution: Change your database password. Make sure that you DO NOT have any symbols in your password.

Problem Explanation: my database was connecting successfully using the server setup example connection strings in the server.cfg. I think the error occurs somewhere in NPWD trying to grab this string from the server.cfg. The special character in the password breaks something. In my example this had a # used.

Error prior to removing symbol from password image

How: Run this command in MariaDB to set a new password

ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourDesiredPasswordHere';
flush privileges;
exit;