From 93ae73ebbaaec0cfe5d9cfd046e4ad26625e9c08 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:28:34 -0500 Subject: [PATCH] fix: rethrow TypeBoxError instead of creating a new one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Valuable information is lost by creating a TransformEncodeError/TransformDecodeError instead of rethrowing the error when it‘s a TypeBoxError, because that error may be a TransformEncodeCheckError/TransformDecodeCheckError, which have an `error` property that tells the caller which property path is the cause. --- src/value/transform/decode.ts | 1 + src/value/transform/encode.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/value/transform/decode.ts b/src/value/transform/decode.ts index 3169293a..ef63096a 100644 --- a/src/value/transform/decode.ts +++ b/src/value/transform/decode.ts @@ -75,6 +75,7 @@ function Default(schema: TSchema, value: any) { try { return IsTransform(schema) ? schema[TransformKind].Decode(value) : value } catch (error) { + if (error instanceof TypeBoxError) throw error throw new TransformDecodeError(schema, value, error) } } diff --git a/src/value/transform/encode.ts b/src/value/transform/encode.ts index 695a7ea7..342ed261 100644 --- a/src/value/transform/encode.ts +++ b/src/value/transform/encode.ts @@ -74,6 +74,7 @@ function Default(schema: TSchema, value: any) { try { return IsTransform(schema) ? schema[TransformKind].Encode(value) : value } catch (error) { + if (error instanceof TypeBoxError) throw error throw new TransformEncodeError(schema, value, error) } }