evidence-dev / evidence

Business intelligence as code: build fast, interactive data visualizations in pure SQL and markdown
https://evidence.dev
MIT License
4.17k stars 198 forks source link

occasional "untitled query" errors #286

Closed mcrascal closed 2 years ago

mcrascal commented 2 years ago

"untitled query" errors occasionally throw during build.

@archiewood do you have any tips on reproducing this?

archiewood commented 2 years ago

Wouldn't describe this as minimum code example, but this will repro it for me:

  1. git clone https://github.com/evidence-dev/demo
    cd demo
    npm install
    npm run dev
  2. Hook up to the SQLite database (needful_things.db)
  3. Navigate to http://localhost:3000/customer/NPS_survey
archiewood commented 2 years ago

This is not super helpful, but I can remove the error if I delete the composed chart from /customer/NPS_survey

ie remove from line 80-87:

<Chart 
    data={data.nps_over_time}
    title='Average NPS Score and # of Reviews (2019 - 2022)'
    subtitle='#,#' >

    <Line y=nps_avg/>
    <Bar y=review_count/>
</Chart>

EDIT: I just need to remove the space in the chart component to remove the error. The below does not throw an error:

<Chart 
    data={data.nps_over_time}
    title='Average NPS Score and # of Reviews (2019 - 2022)'
    subtitle='#,#' >
    <Line y=nps_avg/>
    <Bar y=review_count/>
</Chart>

I get the same error on http://localhost:3000/operations/pick_lists

I can remove this error by deleting the {#each} block:

{#each data.last_7_days_orders as day}

    - [{day.order_date}](/operations/pick_lists/{day.order_date}/)

{/each}
hughess commented 2 years ago

I was able to reproduce the issues with those steps - thanks @archiewood.

I found there was some character in the whitespace that caused the markdown parser to treat the next lines as a query. It worked if I deleted the whitespace, then re-added it myself.

hughess commented 2 years ago

On second thought, it looks like it might have something to with the number of tabs in front of a component

mcrascal commented 2 years ago

This really narrows it down, thanks @archiewood @hughess

mcrascal commented 2 years ago

This was a little tricky, so just documenting:

  1. Remark, the markdown processor that we use to extract sql from code fences, implements the CommonMark markdown spec.
  2. CommonMark includes the ability to create code blocks by indenting text
  3. Mdsvex, the svelte + md processor that process pages into svelte components is built on remark, but it ignores code blocks that have been created by indenting text
  4. I've updated our sql-extraction to ignore indented code blocks in the same way as mdsvex

Will test with the {#each } block scenario above in the AM to confirm edit: seems to resolve that as well