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

astro:db: isDbError functions differently with remote and local DB #10809

Open
1 task
timsexperiments opened this issue Apr 18, 2024 · 2 comments
Open
1 task
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: errors Related to error handling / messages (scope) pkg: db

Comments

@timsexperiments
Copy link

timsexperiments commented Apr 18, 2024

Astro Info

Astro                    v4.6.2
Node                     v21.7.3
System                   macOS (arm64)
Package Manager          bun
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/tailwind
                         astro:db
                         @astrojs/db/file-url

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When running astro with the astro db plugin, the isDbError function is only working when running locally or using a file in the output. However, when running with a remote db the error is getting transformed to an AstroDbError.

{
    "type": "AstroUserError",
    "hint": "See the Astro DB guide for query and push instructions: https://docs.astro.build/en/guides/astro-db/#query-your-database",
    "name": "Astro DB Error",
    "message": "UNIQUE constraint failed: Item.value"
}

This causes the isDbError function to return false:

export function isDbError(err: unknown): err is LibsqlError {
	return err instanceof LibsqlError;
}

Having different expectations for local and remote databases means that code is not testable locally without actually connecting to a remote astro db. This means I need to write different code for local development and my production build.

What's the expected result?

I would expect one of the following:

  • Remote and local runs using the import { db } from 'astro:db' to return the same error no matter what environment (locally, file based, remote).
  • AstroDbError to also return true when running isDbError. However the err is LibsqlError will be false. I would expect a single function that should work for both file based libsql queries and for astro remote db queries.

Link to Minimal Reproducible Example

https://stackblitz.com/~/github.com/timsexperiments/astro-db-test

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Apr 18, 2024
@ematipico ematipico added - P3: minor bug An edge case that only affects very specific usage (priority) feat: errors Related to error handling / messages (scope) pkg: db and removed needs triage Issue needs to be triaged labels Apr 18, 2024
@ematipico
Copy link
Member

cc @bholmesdev

@timsexperiments timsexperiments changed the title Astro DB: isDbError functions differently with remote and local DB astro:db: isDbError functions differently with remote and local DB Apr 18, 2024
@timsexperiments timsexperiments changed the title astro:db: isDbError functions differently with remote and local DB astro:db: isDbError functions differently with remote and local DB Apr 18, 2024
@bholmesdev bholmesdev self-assigned this Apr 18, 2024
@bholmesdev
Copy link
Contributor

Ah thanks for noticing @timsexperiments! The error signature was changed recently, and we missed a test for isDbError() against the remote database. Local and remote should return the same error object. Need to decide whether local should return an AstroError instead, with access to the base LibsqlError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: errors Related to error handling / messages (scope) pkg: db
Projects
None yet
Development

No branches or pull requests

3 participants