You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across a really strange bug. It took me a long time to narrow it down to a minimal repro, so please let me know if anything below is unclear.
Using:
elysia v1.1.5
@elysiajs/eden v1.1.2
The Bug
Using treaty on a very simple endpoint works, but only for the first call. Every second call to this endpoint will fail (even if all incoming parameters & conditions are the same).
constapi=treaty(app);awaitapi.foo.patch({num: '5'});// This worksawaitapi.foo.patch({num: '5'});// This failsawaitapi.foo.patch({num: '5'});// This worksawaitapi.foo.patch({num: '5'});// This fails// etc...
The failure
For the invocations which fail, the stack trace is:
1 | var s=class extends Error{constructor(e,n){super(n+"");this.status=e;this.value=n}};var i=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,o=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,c=/^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/,u=t=>t.trim().length!==0&&!Number.isNaN(Number(t)),d=t=>{if(typeof t!="string")return null;let r=t.replace(/"/g,"");if(i.test(r)||o.test(r)||c.test(r)){let e=new Date(r);if(!Number.isNaN(e.getTime()))return e}return null},a=t=>{let r=t.charCodeAt(0),e=t.charCodeAt(t.length-1);return r===123&&e===125||r===91&&e===93},p=t=>JSON.parse(t,(r,e)=>{ | ... truncated
error: [object Object]
at new s (/myproject/node_modules/.pnpm/@[email protected][email protected]_@[email protected][email protected]_/node_modules/@elysiajs/eden/dist/chunk-XYW4OUFN.mjs:1:44)
at /myproject/node_modules/.pnpm/@[email protected][email protected]_@[email protected][email protected]_/node_modules/@elysiajs/eden/dist/chunk-7WO4HTSU.mjs:1:4302
Conditions
To reproduce this bug you'll need to create an endpoint with the following body schema validation:
import{Elysia,t}from'elysia';constapp=newElysia().patch('/foo',()=>({done: true}),{body: t.Intersect([t.Object({num: t.Optional(// Any digit t.RegExp(/\d/g),),}),t.Object({}),]),},);exportdefaultapp;
This bug only happens if using t.Intersect() and t.Optional() and t.RegExp() (any regex pattern will do). Removing any of these elements, makes the issue go away. Also interestingly, removing the g flag on the RegExp pattern also makes the issue go away.
Because of this behaviour, I can't quite tell if the issue is in elysia or @elysiajs/eden or typebox. Based on the stacktrace, I'm thinking Eden, but I'm not 100% sure.
The text was updated successfully, but these errors were encountered:
I came across a really strange bug. It took me a long time to narrow it down to a minimal repro, so please let me know if anything below is unclear.
Using:
elysia
v1.1.5@elysiajs/eden
v1.1.2The Bug
Using
treaty
on a very simple endpoint works, but only for the first call. Every second call to this endpoint will fail (even if all incoming parameters & conditions are the same).The failure
For the invocations which fail, the stack trace is:
Conditions
To reproduce this bug you'll need to create an endpoint with the following body schema validation:
This bug only happens if using
t.Intersect()
andt.Optional()
andt.RegExp()
(any regex pattern will do). Removing any of these elements, makes the issue go away. Also interestingly, removing theg
flag on theRegExp
pattern also makes the issue go away.Because of this behaviour, I can't quite tell if the issue is in
elysia
or@elysiajs/eden
ortypebox
. Based on the stacktrace, I'm thinking Eden, but I'm not 100% sure.The text was updated successfully, but these errors were encountered: