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

Expose errors in .json mode #159

Open
simonw opened this issue Dec 31, 2023 · 2 comments
Open

Expose errors in .json mode #159

simonw opened this issue Dec 31, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Dec 31, 2023

https://simonwillison.net/dashboard/tag-cloud-by-year.json?year=2023 returns this:

{
  "title": "Tag cloud by year",
  "queries": [
    {
      "sql": "SELECT \"tag\" AS wordcloud_word, COUNT(*) AS wordcloud_count \r\nFROM (\r\n    SELECT blog_tag.tag \r\n    FROM blog_entry_tags \r\n    JOIN blog_tag ON blog_entry_tags.tag_id = blog_tag.id\r\n    JOIN blog_entry ON blog_entry_tags.entry_id = blog_entry.id\r\n    WHERE EXTRACT(YEAR FROM blog_entry.created) = %(year)s\r\nUNION ALL\r\n    SELECT blog_tag.tag \r\n    FROM blog_blogmark_tags \r\n    JOIN blog_tag ON blog_blogmark_tags.tag_id = blog_tag.id\r\n    JOIN blog_blogmark ON blog_blogmark_tags.blogmark_id = blog_blogmark.id\r\n    WHERE EXTRACT(YEAR FROM blog_blogmark.created) = %(year)s\r\nUNION ALL\r\n    SELECT blog_tag.tag \r\n    FROM blog_quotation_tags \r\n    JOIN blog_tag ON blog_quotation_tags.tag_id = blog_tag.id\r\n    JOIN blog_quotation ON blog_quotation_tags.quotation_id = blog_quotation.id\r\n    WHERE EXTRACT(YEAR FROM blog_quotation.created) = %(year)s\r\n) AS results \r\nWHERE tag != 'quora' \r\nGROUP BY \"tag\" \r\nORDER BY wordcloud_count DESC",
      "rows": [
        {
          "wordcloud_word": "ai",
          "wordcloud_count": 342
        },

But https://simonwillison.net/dashboard/tag-cloud-by-year.json returns this:

{
  "title": "Tag cloud by year",
  "queries": [
    {
      "sql": "SELECT \"tag\" AS wordcloud_word, COUNT(*) AS wordcloud_count \r\nFROM (\r\n    SELECT blog_tag.tag \r\n    FROM blog_entry_tags \r\n    JOIN blog_tag ON blog_entry_tags.tag_id = blog_tag.id\r\n    JOIN blog_entry ON blog_entry_tags.entry_id = blog_entry.id\r\n    WHERE EXTRACT(YEAR FROM blog_entry.created) = %(year)s\r\nUNION ALL\r\n    SELECT blog_tag.tag \r\n    FROM blog_blogmark_tags \r\n    JOIN blog_tag ON blog_blogmark_tags.tag_id = blog_tag.id\r\n    JOIN blog_blogmark ON blog_blogmark_tags.blogmark_id = blog_blogmark.id\r\n    WHERE EXTRACT(YEAR FROM blog_blogmark.created) = %(year)s\r\nUNION ALL\r\n    SELECT blog_tag.tag \r\n    FROM blog_quotation_tags \r\n    JOIN blog_tag ON blog_quotation_tags.tag_id = blog_tag.id\r\n    JOIN blog_quotation ON blog_quotation_tags.quotation_id = blog_quotation.id\r\n    WHERE EXTRACT(YEAR FROM blog_quotation.created) = %(year)s\r\n) AS results \r\nWHERE tag != 'quora' \r\nGROUP BY \"tag\" \r\nORDER BY wordcloud_count DESC",
      "rows": []
    }
  ]
}

Actually if you visit https://simonwillison.net/dashboard/tag-cloud-by-year/ you see an error:

CleanShot 2023-12-31 at 13 33 12@2x

@simonw simonw added the enhancement New feature or request label Dec 31, 2023
@simonw
Copy link
Owner Author

simonw commented Dec 31, 2023

Note that it's possible for a page to have some queries that work and others that fail:

CleanShot 2023-12-31 at 13 34 25@2x

So the errors should be in the queries block, maybe like this:

{
  "title": "Tag cloud by year",
  "queries": [
    {
      "sql": "SELECT \"tag\" AS wordcloud_word, COUNT(*) AS wordcloud_count \r\nFROM (\r\n    SELECT blog_tag.tag \r\n    FROM blog_entry_tags \r\n    JOIN blog_tag ON blog_entry_tags.tag_id = blog_tag.id\r\n    JOIN blog_entry ON blog_entry_tags.entry_id = blog_entry.id\r\n    WHERE EXTRACT(YEAR FROM blog_entry.created) = %(year)s\r\nUNION ALL\r\n    SELECT blog_tag.tag \r\n    FROM blog_blogmark_tags \r\n    JOIN blog_tag ON blog_blogmark_tags.tag_id = blog_tag.id\r\n    JOIN blog_blogmark ON blog_blogmark_tags.blogmark_id = blog_blogmark.id\r\n    WHERE EXTRACT(YEAR FROM blog_blogmark.created) = %(year)s\r\nUNION ALL\r\n    SELECT blog_tag.tag \r\n    FROM blog_quotation_tags \r\n    JOIN blog_tag ON blog_quotation_tags.tag_id = blog_tag.id\r\n    JOIN blog_quotation ON blog_quotation_tags.quotation_id = blog_quotation.id\r\n    WHERE EXTRACT(YEAR FROM blog_quotation.created) = %(year)s\r\n) AS results \r\nWHERE tag != 'quora' \r\nGROUP BY \"tag\" \r\nORDER BY wordcloud_count DESC",
      "rows": []
      "error": "error here"
    }
  ]
}

With "error": null for queries that work.

@simonw
Copy link
Owner Author

simonw commented Dec 31, 2023

I think I'll add a "ok": true/false key as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant