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: Astro remote db not returning SQL error info #10810

Closed
1 task done
timsexperiments opened this issue Apr 18, 2024 · 1 comment · Fixed by #11027
Closed
1 task done

astro:db: Astro remote db not returning SQL error info #10810

timsexperiments opened this issue Apr 18, 2024 · 1 comment · Fixed by #11027
Assignees
Labels
- P2: nice to have Not breaking anything but nice to have (priority) 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, I would expect the LibsqlError details to be included in the AstroDbError. This way I can handle different sql error codes (e.g. unique constraint violations) as I want within my code:

Current result:

{
    "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"
}

Example class with added details from original error (utils.ts):

export class AstroDbError extends AstroError {
  name = 'Astro DB Error';
+  cause: string
+
+  constructor(message: string, cause: LibsqlError, hint?: string) {
+    super();
+    this.message = message;
+    this.hint = hint;
+    this.cause = cause;
+  }
}

Example error building with cause as the original error (db-client.ts):

async function parseRemoteError(response: Response): Promise<AstroDbError> {
	...
-	return new AstroDbError(details, hint);
+	return new AstroDbError(details, error, hint);
}

What's the expected result?

I would expect some sort of details about what type of error occurred on the AstroDbError (e.g. SQLITE_CONSTRAINT_UNIQUE):

{
+   "cause": { ... },
    "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"
}

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
@timsexperiments timsexperiments changed the title Astro DB: Astro studio remote db not returning error codes. astro:db: Astro studio remote db not returning error codes. Apr 18, 2024
@timsexperiments timsexperiments changed the title astro:db: Astro studio remote db not returning error codes. astro:db: Astro remote db not returning error codes. Apr 18, 2024
@timsexperiments timsexperiments changed the title astro:db: Astro remote db not returning error codes. astro:db: Astro remote db not returning error codes. Apr 18, 2024
@timsexperiments timsexperiments changed the title astro:db: Astro remote db not returning error codes. astro:db: Astro remote db not returning SQL error info Apr 18, 2024
@matthewp matthewp added - P2: nice to have Not breaking anything but nice to have (priority) pkg: db and removed needs triage Issue needs to be triaged labels Apr 22, 2024
@bholmesdev
Copy link
Contributor

Thanks for reporting this @timsexperiments! We've updated the production error object to a LibsqlError to match development. This will include the e.code property directly on the error, so there's no need for a nested cause for storage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) pkg: db
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants