CronParseErrorRepresents an error that occurs when parsing a cron expression fails.
When to use
Use to handle invalid cron expression failures returned by parse.
Details
This error provides information about what went wrong during parsing, including the error message and optionally the input that caused the error.
Example (Handling cron parse failures)
import { Cron, Result } from "effect"
const result = Cron.parse("invalid expression")
if (Result.isFailure(result)) {
const error: Cron.CronParseError = result.failure
console.log(error.message) // "Invalid number of segments in cron expression"
console.log(error.input) // "invalid expression"
}export class class CronParseErrorclass CronParseError {
name: string;
message: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
input: string | undefined;
}
Represents an error that occurs when parsing a cron expression fails.
When to use
Use to handle invalid cron expression failures returned by parse.
Details
This error provides information about what went wrong during parsing,
including the error message and optionally the input that caused the error.
Example (Handling cron parse failures)
import { Cron, Result } from "effect"
const result = Cron.parse("invalid expression")
if (Result.isFailure(result)) {
const error: Cron.CronParseError = result.failure
console.log(error.message) // "Invalid number of segments in cron expression"
console.log(error.input) // "invalid expression"
}
CronParseError extends import DataData.const TaggedError: <Tag extends string>(
tag: Tag
) => new <A extends Record<string, any> = {}>(
args: Types.VoidIfEmpty<{
readonly [P in keyof A as P extends "_tag"
? never
: P]: A[P]
}>
) => Cause.YieldableError & {
readonly _tag: Tag
} & Readonly<A>
Creates a tagged error class with a _tag discriminator.
When to use
Use when you need domain errors with discriminated-union handling.
Details
Like
Error
, but instances also carry a readonly _tag property,
enabling Effect.catchTag and Effect.catchTags for tag-based recovery.
The _tag is excluded from the constructor argument. Yielding an instance
inside Effect.gen fails the effect with this error.
Example (Recovering by tag)
import { Data, Effect } from "effect"
class NotFound extends Data.TaggedError("NotFound")<{
readonly resource: string
}> {}
class Forbidden extends Data.TaggedError("Forbidden")<{
readonly reason: string
}> {}
const program = Effect.gen(function*() {
return yield* new NotFound({ resource: "/users/42" })
})
const recovered = program.pipe(
Effect.catchTag("NotFound", (e) =>
Effect.succeed(`missing: ${e.resource}`))
)
TaggedError("CronParseError")<{
readonly message: stringmessage: string
readonly input?: string | undefinedinput?: string
}> {
readonly [const CronParseErrorTypeId: "~effect/time/Cron/CronParseError"CronParseErrorTypeId]: typeof const CronParseErrorTypeId: "~effect/time/Cron/CronParseError"CronParseErrorTypeId = const CronParseErrorTypeId: "~effect/time/Cron/CronParseError"CronParseErrorTypeId
}