effect icon indicating copy to clipboard operation
effect copied to clipboard

ConfigError does not expose .message or .toString

Open dmeehan1968 opened this issue 8 months ago • 6 comments

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

dmeehan1968 avatar Apr 13 '25 10:04 dmeehan1968

BTW Actually, you can call .toString(), even though it doesn't show up in autocomplete.

KhraksMamtsov avatar Apr 15 '25 10:04 KhraksMamtsov

@KhraksMamtsov Is there a reason why the ConfigError messages are wrapped in parentheses?

dmeehan1968 avatar Apr 15 '25 15:04 dmeehan1968

I have no idea

KhraksMamtsov avatar Apr 15 '25 16:04 KhraksMamtsov

Can it be removed then as it appears to be inconsistent with other error message formatting?

dmeehan1968 avatar Apr 15 '25 16:04 dmeehan1968

I think this question should be addressed to the team — I just suggested a small improvement. The final decision is up to them.

KhraksMamtsov avatar Apr 15 '25 17:04 KhraksMamtsov

It's probably a poor way of concatenating different messages, we should improve it

mikearnaldi avatar Apr 22 '25 11:04 mikearnaldi