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

[WIP] Debugging docs #266

Open
wants to merge 10 commits into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ const guideMenu = [{
{ text: "Creating Responsive Game Design", link: "/guide/responsive-design" },
{ text: "Create Progressive Web Apps (PWA)", link: "/guide/pwa" },
{ text: "Add TailwindCSS", link: "/guide/tailwindcss" },
{ text: "Upgrade/Update RPGJS", link: "/guide/upgrade" }
{ text: "Upgrade/Update RPGJS", link: "/guide/upgrade" },
{ text: "Debugging server", link: "/debugging/server"},
{ text: "Debugging client", link: "/debugging/client"},
]

},
{
text: 'Advanced',
Expand Down
22 changes: 22 additions & 0 deletions docs/debugging/client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Debuging client

## Chrome dev tools

1. Start game
2. Open dev tools by pressing f12 key
3. Hit ctrl + p to browse your code base
4. Put breakpoints

### If we have error but don't know excatly where

Two options are very usefull during debugging process.

- Caught Exceptions
- Uncaught Exceptions

If you turn them on, debugger automagicly will stop on line where problem is.

![devToolsExceptions](/assets/exceptions-options-devtools.png)

Then we can travel be in time with call stack and find a problem
![devToolsCallstack](/assets/callstack-devtools.png)
Binary file added docs/debugging/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/debugging/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions docs/debugging/server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Debuging server

## Extend package.json

To debug server we need to add inspect flag to our dev command in package.json. It will let us to use our IDE or chrome dev tools to pause on breakpoint on or error.

```
"scripts": {
"build": "rpgjs build",
"dev": "NODE_OPTIONS='--inspect' rpgjs dev",
"start": "node dist/server/main.mjs"
},
```


## Debugging with visual studio code

To debug server with VSC we need to run command `npm run dev` and then attach to node process.

### Add vsc configuration

By clicking on gear we are able to add new debuging config to launch.json

![vscConfig](/assets/vsc-config.png)

Visual Studio code
```
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
}
```

### Start debugger
Then we can attach to process by clicking green play button

![startDebugVsc](/assets/started-debug.png)

## Debuging with chrome

Instead of using IDE we can use chrome dev tools event to debug server. To do this we have to go to url:
- `chrome://inspect`

If we have running server and we added inspect flag we should have inspect button what will lead us to chrome dev tools connected to our server
![chromeInspect](/assets/chrome-inspect.png)

Hit `ctrl + p`` to browse your server side code :)

### If we have error but don't know excatly where

Two options are very usefull during debugging process. If we have some error, but we don't have stack trace (from websockets for instance). We can turn on two options both in VSC and Chrome dev tools

- Caught Exceptions
- Uncaught Exceptions

If you turn them on, debugger automagicly will stop on line where problem is.

![exceptionsOptionsVSC](/assets/exceptions-options-vsc.png)
![exceptionsOptionsDevTools](/assets/exceptions-options-devtools.png)

Then we can go back with call stack and find a problem
![callstackVSC](/assets/callstack-vsc.png)
![callstackDevtools](/assets/callstack-devtools.png)


## Server problem outputs
Errors usually appear in that places:

### Server standard CLI output
![cliErrors](/assets/cli-errors.png)


### Websockets response
![websocketsDevTools](/assets/websockets-in-chrome-dev-tools.png)
20 changes: 20 additions & 0 deletions docs/debugging/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Troubleshooting

## Cannot read properties of undefined (reading 'id')

If on server start you get Cannot read properties of undefined (reading 'id') its highly possible that you put something what was tried to be loaded by autoload and you break recommended structure

For instance if you put smth into main/database/common/smth-common.ts what does not have decorator related to DB.
Put your services and helpers outside of structure ie. main/helpers

## console log source of rpgjs

In command line we can see some error on server start.
![Alt text](image.png)

In this example we have Cannot read properties of undefined (reading 'id'), and stack trace says its in [@rpgjs]/server/src/Scenes/Map.ts:226:38

We cannot leave console.log in Map.ts, bacouse we would have to rebuild library. But we can do this in complied js in same place
[@rpgjs]/server/lib/Scenes/Map.ts

![Alt text](image-1.png)
Binary file added docs/public/assets/callstack-devtools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/assets/callstack-vsc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/assets/chrome-inspect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/assets/cli-errors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/assets/exceptions-options-vsc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/assets/started-debug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/assets/vsc-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.