Empty Query Results Rendering Strangely?

I’d assume someone has already asked about this, but I couldn’t find a similar post.

It seems that queries with empty results are rendered in an odd way. For example:

${query[[
  from index.tag("foo")
]]}

This returns:

||
||
||

Is this expected behavior? It definitely looks a bit strange.
Any insights would be appreciated!

Can confirm but also don’t know what is the reason. I experienced it several times

I’m actually fine with these.
I have some files in the same directory that use very similar queries, some of them return data, and some don’t.
When there’s nothing to return, having this as a placeholder makes it clear to me that it’s intentional.

If it just returned nothing without any indication, that wouldn’t be ideal either.
I haven’t looked at the code, but this is probably how an empty Markdown table is returned by default.

What would you propose?

I’d prefer a simple message such as Error: Query returned no results.

The equivalent query in v1 simply returned nothing.

That appears to be how an empty table is printed. ${{}} prints the same thing. I’m guessing it’s the start of the table markdown, but it’s not recognized as markdown because too much is missing.

I’m would prefer either no change or printing nothing. That way we can handle empty queries with a specific message more easily. You can have queries with no results return nothing instead of the empty table with ${query[[from index.tag "foo"]] or ""}, or you can put your own message ${query[[from index.tag "foo" ]] or "No foo found, everything is bar"}.

3 Likes

I recently implemented a similar feature for displaying the query with template function:

I agree that query... or "nothing" is a nice Lua-ism, and it works right now. However, I expect a bunch of other places to fail gracefully with empty table and freak out with nil, so we should test it well before merging.

I think this should clear up the confusion with empty results and document a way to make them nicer. Thanks @lochel for pointing this out, it’s been in SilverBullet for ages but I never really put some thought into it. In the end it was just a two-line change :smiley:

And I just merged it. Thanks. It was silly that I never fixed this even I see it all the time also.