TraversalError when using nested matches as morphs.
Running the following, I get a TraversalError:
I get the following output:
Swapping the order of RepositoryID's cases fixes the issue:
If an error occurs within a morph of a case, I would expect match to fallthrough and evaluate the next case. Is this expected behaviour?
import { match, type } from "arktype";
const WrappedUUID = type("/^\{(.*)\}$/")
.pipe((v) => v.slice(1, -1))
.to("string.uuid");
const UUID = type("string")
.pipe.try(
match
.case(WrappedUUID, (v) => v)
.case("string.uuid", (v) => v)
.default("assert"),
)
.brand("uuid");
type UUID = typeof UUID.infer;
const StashID = type("string.integer").brand("stash-id");
type StashID = typeof StashID.infer;
const RepositoryID = type("string").pipe.try(
match
.case(UUID, (v) => v as UUID)
.case(StashID, (v) => v as StashID)
.default("assert"),
);
type RepositoryID = typeof RepositoryID.infer;
console.log("WrappedUUID:", WrappedUUID.assert("{c396775f-05e6-4392-8537-179a805c0047}"));
console.log("UUID:", UUID.assert("c396775f-05e6-4392-8537-179a805c0047"));
console.log("StashID:", StashID.assert("12345"));
console.log("RepositoryID (WrappedUUID):", RepositoryID.assert("{c396775f-05e6-4392-8537-179a805c0047}"));
console.log("RepositoryID (UUID):", RepositoryID.assert("c396775f-05e6-4392-8537-179a805c0047"));
console.log("RepositoryID (StashID):", RepositoryID.assert("12345"));import { match, type } from "arktype";
const WrappedUUID = type("/^\{(.*)\}$/")
.pipe((v) => v.slice(1, -1))
.to("string.uuid");
const UUID = type("string")
.pipe.try(
match
.case(WrappedUUID, (v) => v)
.case("string.uuid", (v) => v)
.default("assert"),
)
.brand("uuid");
type UUID = typeof UUID.infer;
const StashID = type("string.integer").brand("stash-id");
type StashID = typeof StashID.infer;
const RepositoryID = type("string").pipe.try(
match
.case(UUID, (v) => v as UUID)
.case(StashID, (v) => v as StashID)
.default("assert"),
);
type RepositoryID = typeof RepositoryID.infer;
console.log("WrappedUUID:", WrappedUUID.assert("{c396775f-05e6-4392-8537-179a805c0047}"));
console.log("UUID:", UUID.assert("c396775f-05e6-4392-8537-179a805c0047"));
console.log("StashID:", StashID.assert("12345"));
console.log("RepositoryID (WrappedUUID):", RepositoryID.assert("{c396775f-05e6-4392-8537-179a805c0047}"));
console.log("RepositoryID (UUID):", RepositoryID.assert("c396775f-05e6-4392-8537-179a805c0047"));
console.log("RepositoryID (StashID):", RepositoryID.assert("12345"));I get the following output:
WrappedUUID: c396775f-05e6-4392-8537-179a805c0047
UUID: c396775f-05e6-4392-8537-179a805c0047
StashID: 12345
RepositoryID (WrappedUUID): c396775f-05e6-4392-8537-179a805c0047
RepositoryID (UUID): c396775f-05e6-4392-8537-179a805c0047
141 | /**
142 | * Converts ArkErrors to TraversalError, a subclass of `Error` suitable for throwing with nice
143 | * formatting.
144 | */
145 | toTraversalError() {
146 | return new TraversalError(this);
^
TraversalError: must be matched by ^{(.*)}$ or a UUID (was "12345")
at toTraversalError (<redacted>/node_modules/@ark/schema/out/shared/errors.js:146:16)
at throw (<redacted>/node_modules/@ark/schema/out/shared/errors.js:139:20)
at <redacted>/demo.ts:30:53
at loadAndEvaluateModule (2:1)
Bun v1.3.1 (macOS arm64)WrappedUUID: c396775f-05e6-4392-8537-179a805c0047
UUID: c396775f-05e6-4392-8537-179a805c0047
StashID: 12345
RepositoryID (WrappedUUID): c396775f-05e6-4392-8537-179a805c0047
RepositoryID (UUID): c396775f-05e6-4392-8537-179a805c0047
141 | /**
142 | * Converts ArkErrors to TraversalError, a subclass of `Error` suitable for throwing with nice
143 | * formatting.
144 | */
145 | toTraversalError() {
146 | return new TraversalError(this);
^
TraversalError: must be matched by ^{(.*)}$ or a UUID (was "12345")
at toTraversalError (<redacted>/node_modules/@ark/schema/out/shared/errors.js:146:16)
at throw (<redacted>/node_modules/@ark/schema/out/shared/errors.js:139:20)
at <redacted>/demo.ts:30:53
at loadAndEvaluateModule (2:1)
Bun v1.3.1 (macOS arm64)Swapping the order of RepositoryID's cases fixes the issue:
WrappedUUID: c396775f-05e6-4392-8537-179a805c0047
UUID: c396775f-05e6-4392-8537-179a805c0047
StashID: 12345
RepositoryID (WrappedUUID): c396775f-05e6-4392-8537-179a805c0047
RepositoryID (UUID): c396775f-05e6-4392-8537-179a805c0047
RepositoryID (StashID): 12345WrappedUUID: c396775f-05e6-4392-8537-179a805c0047
UUID: c396775f-05e6-4392-8537-179a805c0047
StashID: 12345
RepositoryID (WrappedUUID): c396775f-05e6-4392-8537-179a805c0047
RepositoryID (UUID): c396775f-05e6-4392-8537-179a805c0047
RepositoryID (StashID): 12345If an error occurs within a morph of a case, I would expect match to fallthrough and evaluate the next case. Is this expected behaviour?