Skip to content

Commit 546fdeb

Browse files
KhraksMamtsoveffect-bot
authored andcommitted
Add property message: string to ConfigError.And & Or (#4743)
1 parent 62c257d commit 546fdeb

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

.changeset/sixty-ducks-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": minor
3+
---
4+
5+
property `message: string` has been added to `ConfigError.And` & `Or` members

packages/effect/src/ConfigError.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export interface And extends ConfigError.Proto {
7676
readonly _op: "And"
7777
readonly left: ConfigError
7878
readonly right: ConfigError
79+
readonly message: string
7980
}
8081

8182
/**
@@ -86,6 +87,7 @@ export interface Or extends ConfigError.Proto {
8687
readonly _op: "Or"
8788
readonly left: ConfigError
8889
readonly right: ConfigError
90+
readonly message: string
8991
}
9092

9193
/**

packages/effect/src/internal/configError.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export const And = (self: ConfigError.ConfigError, that: ConfigError.ConfigError
3232
return `${this.left} and ${this.right}`
3333
}
3434
})
35+
Object.defineProperty(error, "message", {
36+
enumerable: false,
37+
get(this: ConfigError.And) {
38+
return this.toString()
39+
}
40+
})
3541
return error
3642
}
3743

@@ -47,6 +53,12 @@ export const Or = (self: ConfigError.ConfigError, that: ConfigError.ConfigError)
4753
return `${this.left} or ${this.right}`
4854
}
4955
})
56+
Object.defineProperty(error, "message", {
57+
enumerable: false,
58+
get(this: ConfigError.Or) {
59+
return this.toString()
60+
}
61+
})
5062
return error
5163
}
5264

packages/effect/test/Config.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,4 +632,20 @@ describe("Config", () => {
632632
)
633633
deepStrictEqual(result, [1, 2, 3])
634634
})
635+
636+
it("ConfigError message", () => {
637+
const missingData = ConfigError.MissingData(["PATH"], "missing PATH")
638+
const invalidData = ConfigError.InvalidData(["PATH1"], "invalid PATH1")
639+
const andError = ConfigError.And(missingData, invalidData)
640+
const orError = ConfigError.Or(missingData, invalidData)
641+
642+
strictEqual(
643+
andError.message,
644+
"(Missing data at PATH: \"missing PATH\") and (Invalid data at PATH1: \"invalid PATH1\")"
645+
)
646+
strictEqual(
647+
orError.message,
648+
"(Missing data at PATH: \"missing PATH\") or (Invalid data at PATH1: \"invalid PATH1\")"
649+
)
650+
})
635651
})

0 commit comments

Comments
 (0)