arktype icon indicating copy to clipboard operation
arktype copied to clipboard

Custom error messages don't work on morph

Open robin-blanchard opened this issue 6 months ago • 0 comments

Report a bug

I am trying to have custom error messages on morphs. Here is an example for a Port type.

The error message is still the original one from Arktype.

🔎 Search Terms

morph, error, configure

🧩 Context

  • ArkType version: 2.1.20
  • TypeScript version (5.1+): 5.6.2

🧑‍💻 Repro

Playground Link: https://arktype.io/playground?code=import%20%7B%20type%20%7D%20from%20%22arktype%22%0A%0Aconst%20Thing%20%3D%20type(%22string.numeric.parse%20%7C%20number%22)%0A%09.to(%220%3Cnumber%3C%3D65535%22)%0A%09.configure(%7B%0A%09%09message%3A%20(ctx)%20%3D%3E%20%7B%0A%09%09%09return%20%22This%20is%20a%20custom%20error%22%0A%09%09%7D%0A%09%7D)%0A%0A%2F%2F%20const%20out%20%3D%20Thing(%22abcd%22)%20%2F%2F%20Shows%20custom%20error%0Aconst%20out%20%3D%20Thing(%22999999%22)%20%2F%2F%20Shows%20default%20error%0A%0A

import { type } from "arktype"

const Thing = type("string.numeric.parse | number")
    .to("0<number<=65535")
    .configure({
        message: (ctx) => {
            return "This is a custom error"
        }
    })

// const out = Thing("abcd") // Shows custom error
const out = Thing("999999") // Shows default error

robin-blanchard avatar Jul 16 '25 14:07 robin-blanchard