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

[Bug] SQLite error parsing issue #1098

Closed
danconnell opened this issue Sep 12, 2024 · 1 comment · Fixed by #1177
Closed

[Bug] SQLite error parsing issue #1098

danconnell opened this issue Sep 12, 2024 · 1 comment · Fixed by #1177

Comments

@danconnell
Copy link

Seeing TypeError: parameters.reduce is not a function when a SQLite error occurs.

Coming from this code

          let parameters = (args[0] ?? []) as string[];
          parameters =
            parameters.length <= 25
              ? parameters
              : parameters.slice(0, 26).concat(["..."]);
          const params = parameters.reduce<Record<number, any>>(
            (acc, parameter, idx) => {
              acc[idx + 1] = parameter;
              return acc;
            },
            {},
          );

located at https://github.com/ponder-sh/ponder/blob/main/packages/core/src/utils/sqlite.ts#L40

This is happening because parameters is a string and represents the first arg that was passed to the query as this code is currently written.

I'm not sure what exactly the intention is with this code, but perhaps it should be something more along the lines of this

          const params = (args ?? []).reduce<Record<number, any>>(
            (acc, parameter, idx) => {
              acc[idx + 1] = parameter.length <= 25
              ? parameter
              : parameter.slice(0, 26).concat(["..."]);
              return acc;
            },
            {},
          );

As it is right now, when a SQLite error occurs it's impossible to see the actual error that did occur because of this TypeError happening. So perhaps also worth adding a try/catch around this error parsing as well.

In case it's relevant, the error I was receiving was a integer overflow error from using sum on a bigint column with negative values and the EVM_MIN_INT encoding that is done by this repo causing that sum operation to overflow

@danconnell danconnell changed the title SQLite error parsing issue [Bug] SQLite error parsing issue Sep 12, 2024
@0xOlias
Copy link
Collaborator

0xOlias commented Sep 12, 2024

Yea, this error parsing code is a bit cursed - thanks for flagging. Will work on a reproduction + fix.

@kyscott18 kyscott18 mentioned this issue Oct 3, 2024
4 tasks
@kyscott18 kyscott18 mentioned this issue Oct 21, 2024
@kyscott18 kyscott18 linked a pull request Oct 21, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from Todo to Done in Ponder Roadmap Nov 8, 2024
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