GithubHelp home page GithubHelp logo

Comments (2)

Dhruv-Garg79 avatar Dhruv-Garg79 commented on September 21, 2024 1

Hey @sinclairzx81, I was able to figure it out later on. The issue was, that the UUID from Scylla was getting passed on as int array buffer, but in the error message of typebox, it was coming as a string value, which led to the confusion.

Even in the logs it was coming up at us string value since I was using Pino logger. Until I checked with console.log, I wasn't able to figure it out.

it's working as expected now.

from typebox.

sinclairzx81 avatar sinclairzx81 commented on September 21, 2024

@Dhruv-Garg79 Hi, That's a strange error.

I don't seem to be able to replicate the issue locally... here's the code I'm using (you can run this locally to repro)

import { TypeCompiler } from '@sinclair/typebox/compiler'
import { Type, FormatRegistry } from '@sinclair/typebox'
import { Value } from '@sinclair/typebox/value'

FormatRegistry.Set('uuid', value => IsUuid(value))

const Uuid = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i

export function IsUuid(value: string): boolean {
  return Uuid.test(value)
}
// ...Test

const T = Type.Object({ id: Type.String({ format: 'uuid' }) })

const A = TypeCompiler.Compile(T).Check({ id: 'f00b12d9-b2af-48ab-8b00-25070afbe307' })

const B = Value.Check(T, { id: String('f00b12d9-b2af-48ab-8b00-25070afbe307') })

const C = [...Value.Errors(T, { id: String('f00b12d9-b2af-48ab-8b00-25070afbe307') })]

console.log(A, B, C) // true, true, [] - ok

So the above is fine, however the error you've posted is somewhat puzzling as the /id value passed on the error certainly appears to be a string. I'm not sure how this could happen...breakdown of the error below...

[{
  "type":54,                                         // ok:  error type string
  "schema": { "format":"uuid", "type":"string" },    // ok: a string with format
  "path": "/id",                                     // ok: path looks correct
  "value": "f00b12d9-b2af-48ab-8b00-25070afbe307",   // puzzle: but the value is string?
  "message": "Expected string"                       // ok: 
}]

Could you run a quick test on the id value to see what type it is....

console.log(typeof value.id === 'string') // should print true

... the only thing I can think of is that id somehow isn't a string....

const A = String('hello world')

const B = Object.assign(A, {}) // is it possible the id might be assigned things?

console.log(typeof A) // string - ok

console.log(typeof B) // object - not a string - but still string-like

Outside of the above guess, there's not too much else to go on. Just check there's nothing unusual about the id (i.e. some database drivers may create specialized string values for identifiers). It's a curious error, but need more information to provide additional help.

Let me know how you go.
Cheers
S

from typebox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.