Skip to content

Commit 65c5f1d

Browse files
committed
feat: improve errors and tasks
1 parent 9e377af commit 65c5f1d

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

Taskfile.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
version: 3
22

33
tasks:
4-
build:
5-
desc: "Compile library"
6-
cmd: go build -o ./bin/main .
7-
84
test:
95
desc: "Execute tests"
106
cmd: go test -v ./... -timeout 1m {{.CLI_ARGS}}

pkg/container/container_fill.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ func (c Container) Fill(structPointer any) (err error) {
4141
instance, err = c.resolve(fieldValue.Type())
4242
}
4343
if err != nil {
44-
return err
44+
// Wrap error
45+
customError, ok := err.(*errors.WiringError)
46+
if !ok {
47+
return err
48+
}
49+
return errors.Errorf(
50+
customError.Code(),
51+
"cannot resolve dependency for field %s.%s: %w",
52+
refStructType.Name(),
53+
refStructType.Field(i).Name,
54+
customError)
4555
}
4656

4757
fieldValue.Set(instance)

pkg/errors/wiring_error.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ func (e *WiringError) Error() string {
3232
func (e *WiringError) Unwrap() error {
3333
return e.err
3434
}
35+
36+
func (e WiringError) Code() wiringErrorCode {
37+
return e.code
38+
}

0 commit comments

Comments
 (0)