# Debugging query plug

**URL:** <https://community.silverbullet.md/t/debugging-query-plug/1289>\
**Category:** v1: Troubleshooting (legacy)\
**Created:** [November 21, 2024, 4:00pm UTC](https://community.silverbullet.md/t/debugging-query-plug/1289 "2024-11-21T16:00:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nightscape](https://community.silverbullet.md/user_avatar/community.silverbullet.md/nightscape/32/754_2.png) [@nightscape](https://community.silverbullet.md/u/nightscape)\
**Post date:** [November 21, 2024, 4:00pm UTC](https://community.silverbullet.md/t/debugging-query-plug/1289/1 "2024-11-21T16:00:34Z")

</div>

Hi, I started with some query plug implementations, but I’m having real difficulties finding out why my plugs return only empty data.  
When I’m writing a command everything is going smooth, I can see the service workers in the Sources tab in my browser, set breakpoints there and see the output of `console.log`.  
However, when I try to write a method that reacts to `events: ["query:something"]` the execution seems to happen in the backend, I can’t set breakpoints in the compiled `_plug/something.plug.js` and `console.log` output doesn’t appear anywhere.

Can someone give me some tips on how to debug / find out what is happening inside my plug code in that case?

---

<div class="post-metadata">

**Author:** ![Maarrk](https://community.silverbullet.md/user_avatar/community.silverbullet.md/maarrk/32/56_2.png) [@Maarrk](https://community.silverbullet.md/u/Maarrk)\
**Post date:** [November 22, 2024, 12:28am UTC](https://community.silverbullet.md/t/debugging-query-plug/1289/2 "2024-11-22T00:28:27Z")

</div>

Hi, have you tried running the silverbullet server from source? Even if I’m developing a plug I tend to do that, so I have a chance to look at the main application code, and not mess up my regular notes.

Recently I was doing something about indexing (which happens on backend) and I did get my `console.log` output in the terminal in which I ran `deno task watch-server ./test_space` from [README in main repo](https://github.com/silverbulletmd/silverbullet?tab=readme-ov-file#developing-silverbullet)

---

<div class="post-metadata">

**Author:** ![nightscape](https://community.silverbullet.md/user_avatar/community.silverbullet.md/nightscape/32/754_2.png) [@nightscape](https://community.silverbullet.md/u/nightscape)\
**Post date:** [November 22, 2024, 7:22am UTC](https://community.silverbullet.md/t/debugging-query-plug/1289/3 "2024-11-22T07:22:07Z")

</div>

I’m running the server through a debugging session in VS Code. I can see an RPC for the `query` plugin being made and follow that up to some point in a Deno library in `11_worker.js` where it gets too asynchronous for me to understand what’s happening 😬  
I can see the ordinary server logs in the console, but nothing I `console.log` or `console.error` from my plug…

---

<div class="post-metadata">

**Author:** ![Maarrk](https://community.silverbullet.md/user_avatar/community.silverbullet.md/maarrk/32/56_2.png) [@Maarrk](https://community.silverbullet.md/u/Maarrk)\
**Post date:** [November 22, 2024, 11:06am UTC](https://community.silverbullet.md/t/debugging-query-plug/1289/4 "2024-11-22T11:06:42Z")

</div>

That is rather surprising, because the logs I was getting are also from a plug: [silverbullet/plugs/index/page\_links.ts at 8114b2547009da984e77267c14f7cc7f1b0e4d48 · silverbulletmd/silverbullet · GitHub](https://github.com/silverbulletmd/silverbullet/blob/8114b2547009da984e77267c14f7cc7f1b0e4d48/plugs/index/page_links.ts#L249)  
Maybe it was different because it’s one of the built-in ones? Sorry, can’t think of anything more.

Have you considered using the `editor.flashNotification` syscall? I know it’s much less convenient than `console.log`, but maybe it’ll help you figure out the normal logging?

---

<div class="post-metadata">

**Author:** ![nightscape](https://community.silverbullet.md/user_avatar/community.silverbullet.md/nightscape/32/754_2.png) [@nightscape](https://community.silverbullet.md/u/nightscape)\
**Post date:** [November 22, 2024, 12:57pm UTC](https://community.silverbullet.md/t/debugging-query-plug/1289/5 "2024-11-22T12:57:01Z")

</div>

I think somehow `query` functions are executed differently than others. I didn’t have any issues with `command` functions.  
In `query` functions you also can’t use `editor.flashNotification`, it throws an exception.  
We probably need @zef for clarification and best practices 🙂

---

<div class="post-metadata">

**Author:** ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)\
**Post date:** [November 22, 2024, 5:38pm UTC](https://community.silverbullet.md/t/debugging-query-plug/1289/6 "2024-11-22T17:38:50Z")

</div>

Template and query rendering is indeed delegated to the server, except when you run in Sync mode. So if you want to run a debugger, that may be the way to do that. Honestly, I don’t use debuggers myself (yikes), I’m more of a console.log debuggers.

On that topic, console.log should work perfectly fine also for this purpose, except of course that since queries and templates are executed on the server, console.logs will also appear on the server log (standard output) instead of in the browser. So perhaps you were looking in the wrong place?
