ConfigErrorRepresents the error type produced when config loading or validation fails.
When to use
Use when you need to inspect config loading or validation failures.
Details
Wraps either:
- A
SourceError— the provider could not read data (I/O failure). - A
SchemaError— the data was found but did not match the schema (wrong type, out of range, missing key, etc.).
export class class ConfigErrorclass ConfigError {
_tag: 'ConfigError';
name: string;
cause: SourceError | Schema.SchemaError;
message: string;
toString: () => string;
}
Represents the error type produced when config loading or validation fails.
When to use
Use when you need to inspect config loading or validation failures.
Details
Wraps either:
- A
SourceError — the provider could not read data (I/O failure).
- A
SchemaError — the data was found but did not match the schema
(wrong type, out of range, missing key, etc.).
ConfigError {
readonly ConfigError._tag: "ConfigError"_tag = "ConfigError"
readonly ConfigError.name: stringname: string = "ConfigError"
readonly ConfigError.cause: SourceError | Schema.SchemaErrorcause: class SourceErrorclass SourceError {
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;
}
Typed error indicating that a configuration source could not be read.
When to use
Use when you need to report that a custom provider's underlying store is
unreachable or produced an I/O error while reading configuration data.
Gotchas
Do not use SourceError for "key not found". That case is represented by
returning undefined from load.
Example (Failing with a SourceError)
import { ConfigProvider, Effect } from "effect"
const provider = ConfigProvider.make((_path) =>
Effect.fail(
new ConfigProvider.SourceError({ message: "connection refused" })
)
)
SourceError | import SchemaSchema.class SchemaError
export SchemaError
class SchemaError {
message: string;
toString: () => string;
name: 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; <…;
toJSON: () => unknown;
_tag: Tag;
issue: SchemaIssue.Issue;
}
Error thrown (or returned as the error channel value) when schema decoding
or encoding fails.
Details
The issue field contains a structured
SchemaIssue.Issue
tree describing
every validation failure, including the path to the problematic value,
expected types, and actual values received. message renders the issue tree
as a human-readable string.
Use
isSchemaError
to narrow an unknown value to SchemaError.
Example (Catching a SchemaError)
import { Schema } from "effect"
try {
Schema.decodeUnknownSync(Schema.Number)("not a number")
} catch (err) {
if (Schema.isSchemaError(err)) {
console.log(err.message)
// Expected number, actual "not a number"
}
}
SchemaError
constructor(cause: SourceError | Schema.SchemaErrorcause: class SourceErrorclass SourceError {
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;
}
Typed error indicating that a configuration source could not be read.
When to use
Use when you need to report that a custom provider's underlying store is
unreachable or produced an I/O error while reading configuration data.
Gotchas
Do not use SourceError for "key not found". That case is represented by
returning undefined from load.
Example (Failing with a SourceError)
import { ConfigProvider, Effect } from "effect"
const provider = ConfigProvider.make((_path) =>
Effect.fail(
new ConfigProvider.SourceError({ message: "connection refused" })
)
)
SourceError | import SchemaSchema.class SchemaError
export SchemaError
class SchemaError {
message: string;
toString: () => string;
name: 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; <…;
toJSON: () => unknown;
_tag: Tag;
issue: SchemaIssue.Issue;
}
Error thrown (or returned as the error channel value) when schema decoding
or encoding fails.
Details
The issue field contains a structured
SchemaIssue.Issue
tree describing
every validation failure, including the path to the problematic value,
expected types, and actual values received. message renders the issue tree
as a human-readable string.
Use
isSchemaError
to narrow an unknown value to SchemaError.
Example (Catching a SchemaError)
import { Schema } from "effect"
try {
Schema.decodeUnknownSync(Schema.Number)("not a number")
} catch (err) {
if (Schema.isSchemaError(err)) {
console.log(err.message)
// Expected number, actual "not a number"
}
}
SchemaError) {
this.ConfigError.cause: SourceError | Schema.SchemaErrorcause = cause: SourceError | Schema.SchemaErrorcause
}
get ConfigError.message: stringmessage() {
return this.ConfigError.cause: SourceError | Schema.SchemaErrorcause.function toString(): stringReturns a string representation of an object.
toString()
}
ConfigError.toString(): stringtoString() {
return `ConfigError(${this.ConfigError.message: stringmessage})`
}
}