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

tslog error when logging error with multiple constructor arguments #4179

Closed
justinsmid opened this issue Jul 25, 2023 · 1 comment · Fixed by #4180
Closed

tslog error when logging error with multiple constructor arguments #4179

justinsmid opened this issue Jul 25, 2023 · 1 comment · Fixed by #4180
Assignees
Labels
kind/bug Something isn't working status/done

Comments

@justinsmid
Copy link
Contributor

justinsmid commented Jul 25, 2023

What is the problem?

I have recently started running into a tslog issue that causes tslog to crash when you attempt to log an error whose class' constructor has multiple arguments.

My particular case occurs when using blitz with prisma, upgrading prisma to 5.0.0, and then running an invalid query or mutation (e.g. using select: { idd: true } instead of select: { id: true }). It can be reproduced by following blitz's getting started steps, upgrading prisma to v5, and calling such an invalid mutation query/mutation, as I have done in this reproduction repo: https://github.com/justinsmid/blitz-prisma-clientversion-error-reproduction

The issue appears to have been introduced in tslog version 4.7.5, and the listed workaround in the issue mentioned above appears to be to downgrade tslog to 4.7.4, which I would simply do, except it's not my code that's using tslog, it's blitz.
More specifically, this line is the one causing the issue in my case.

Would downgrading tslog to 4.7.4 be an option for you guys, or would you recommend I try and figure out a workaround on my end?

Paste all your error logs here:

TypeError: Cannot destructure property 'clientVersion' of 'undefined' as it is undefined.
     at new PrismaClientValidationError (/[REDACTED]/node_modules/@prisma/client-mysql/runtime/library.js:26:2545)
     at Logger._cloneError (/[REDACTED]/node_modules/.pnpm/[email protected]/node_modules/tslog/dist/cjs/BaseLogger.js:238:26)
     at Logger._recursiveCloneAndMaskValuesOfKeys (/[REDACTED]/node_modules/.pnpm/[email protected]/node_modules/tslog/dist/cjs/BaseLogger.js:183:41)
     at /[REDACTED]/node_modules/.pnpm/[email protected]/node_modules/tslog/dist/cjs/BaseLogger.js:157:25
     at Array.map (<anonymous>)
     at Logger._mask (/{REDACTED]/node_modules/.pnpm/[email protected]/node_modules/tslog/dist/cjs/BaseLogger.js:156:22)
     at Logger.log (/{REDACTED]/node_modules/.pnpm/[email protected]/node_modules/tslog/dist/cjs/BaseLogger.js:99:24)
     at Logger.error (/{REDACTED]/node_modules/.pnpm/[email protected]/node_modules/tslog/dist/cjs/index.js:29:22)
     at /{REDACTED]/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected]/node_modules/@blitzjs/rpc/dist/index-server.cjs:326:15
     at Generator.throw (<anonymous>)
     at rejected (/{REDACTED]/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected][email protected]/node_modules/@blitzjs/rpc/dist/index-server.cjs:127:29)     

Paste all relevant code snippets here:

// blitz-server.ts
export const { gSSP, gSP, api } = setupBlitzServer({
  plugins: [],
  logger: BlitzLogger({}),
})
// Query
import { resolver } from "@blitzjs/rpc"
import db from "db"

const QueryThatErrors = resolver.pipe(
  async () => {
    return await db.user.findFirst({
      select: {
        idd: true,
      }
    })
  },
)

export default QueryThatErrors
// Query consumer
const [result] = useQuery(QueryThatErrors, null, { suspense: false })

What are detailed steps to reproduce this?

  1. Follow blitz's getting started steps
    • blitz new myAppName
    • cd myAppName
  2. Upgrade prisma to v5
  3. Create an invalid query (see snippet above for example)
  4. Call the invalid query using useQuery (see snippet above for example)
  5. Start the server
    • pnpm run dev
  6. Go to http://localhost:3000
  7. Look at the server console to see the error

Alternatively, go to my reproduction repository where I have already done these steps and follow the README's steps

Run blitz -v and paste the output here:

Blitz version: 2.0.0-beta.31 (global)
Blitz version: 2.0.0-beta.31 (local)
Linux 5.4 | linux-x64 | Node: v16.16.0


 Package manager: pnpm

  System:
    OS: Linux 5.4 Linux Mint 20.2 (Uma)
    CPU: (4) x64 Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz
    Memory: 7.03 GB / 31.28 GB
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v16.16.0/bin/npm
  npmPackages:
    @blitzjs/auth: 2.0.0-beta.31 => 2.0.0-beta.31 
    @blitzjs/next: 2.0.0-beta.31 => 2.0.0-beta.31 
    @blitzjs/rpc: 2.0.0-beta.31 => 2.0.0-beta.31 
    @prisma/client: 5.0.0 => 5.0.0 
    blitz: 2.0.0-beta.31 => 2.0.0-beta.31 
    next: 13.4.5 => 13.4.5 
    prisma: 5.0.0 => 5.0.0 
    react: 18.2.0 => 18.2.0 
    react-dom: 18.2.0 => 18.2.0 
    typescript: ^4.8.4 => 4.8.4 

Please include below any other applicable logs and screenshots that show your problem:

No response

@justinsmid justinsmid added kind/bug Something isn't working status/triage labels Jul 25, 2023
@siddhsuresh
Copy link
Member

Hey @justinsmid thanks for the issue, downgrading tslog to 4.7.4 can certainly be done.

Please feel free to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working status/done
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants