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

Error isn't handled #3

Closed
rawnly opened this issue Sep 25, 2022 · 1 comment · Fixed by #4
Closed

Error isn't handled #3

rawnly opened this issue Sep 25, 2022 · 1 comment · Fixed by #4

Comments

@rawnly
Copy link
Contributor

rawnly commented Sep 25, 2022

const results = await this.#conn.execute(compiledQuery.sql, parameters)
return {
rows: results.rows as O[],
numUpdatedOrDeletedRows: results.rowsAffected == null ? undefined : BigInt(results.rowsAffected),
}
}

The error inside the executeQuery method is not handled. execute returns an object described as the following:

export interface ExecutedQuery {
    headers: string[];
    types: Types;
    rows: Row[];
    size: number;
    statement: string;
    insertId: string | null;
    rowsAffected: number | null;
    error: VitessError | null;
    time: number;
}

A simple fix is to add

if (results.error) {
    throw results.error;
}
@rawnly rawnly mentioned this issue Sep 25, 2022
@jacobwgillespie
Copy link
Member

@rawnly thanks for the quick PR, this has been released in version v0.2.1! 🎉

One note, @planetscale/database now natively throws errors as of 1.3.0 (planetscale/database-js#62), so you may want to upgrade that package as well. That said, with your fix here, it'll work for versions <1.3.0. 👍

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

Successfully merging a pull request may close this issue.

2 participants