Skip to content

ConfigError does not expose .message or .toString #4722

@dmeehan1968

Description

@dmeehan1968

What version of Effect is running?

3.14.5

What steps can reproduce the bug?

Config methods that return compound conditions (such as nonEmptyString) produce a ConfigError that may lead with a And or Or tag type which does not expose a message attribute. If one wants map errors and provide context to the underlying fault (such as a process mis-configuration through a HTTP 500 response) ConfigError needs to be handled as a special case compared to other Effect standard errors (ParseError etc).

Config.nonEmptyString('XYZ').pipe(Effect.catchTag('ConfigError', err => Effect.succeed(err.message)))
TS2339: Property message does not exist on type ConfigError
Property message does not exist on type And

Playground

What is the expected behavior?

ConfigError should behave like other Effect standard errors and expose a .message attribute when the error is a compound and is represented by And or Or.

Config.nonEmptyString('XYZ').pipe(Effect.catchTag('ConfigError', err => Effect.succeed(err.message)))

This would allow ConfigError to be treated like other errors rather than as a special case

Config.nonEmptyString('XYZ').pipe(Effect.catchAll(err => Effect.succeed(err.message)))

What do you see instead?

Config.nonEmptyString('XYZ').pipe(Effect.catchTag('ConfigError', err => Effect.succeed(err.message)))
TS2339: Property message does not exist on type ConfigError
Property message does not exist on type And

Additional information

Workaround:

Config.nonEmptyString('XYZ').pipe(Effect.catchTag('ConfigError', err => Effect.succeed(String(err))))

gives:

(Missing data at XYZ: "Expected XYZ to exist in the process context")

Note: This isn't ideal as the parentheses are not normally included in a .message attribute.

From Discord

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions