ConfigError does not expose .message or .toString
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
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
BTW Actually, you can call .toString(), even though it doesn't show up in autocomplete.
@KhraksMamtsov Is there a reason why the ConfigError messages are wrapped in parentheses?
I have no idea
Can it be removed then as it appears to be inconsistent with other error message formatting?
I think this question should be addressed to the team — I just suggested a small improvement. The final decision is up to them.
It's probably a poor way of concatenating different messages, we should improve it