Skip to content

Commit 6748e44

Browse files
committed
refactor(sdk): replace error message with custom error type
Improve error handling by introducing a custom error type `VersionNotExistsError` for better clarity and maintainability
1 parent 5f2bd79 commit 6748e44

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

internal/sdk.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ func (b *Sdk) PreUse(version Version, scope UseScope) (Version, error) {
379379
return newVersion, nil
380380
}
381381

382+
type VersionNotExistsError struct {
383+
Label string
384+
}
385+
386+
func (e *VersionNotExistsError) Error() string {
387+
return fmt.Sprintf("%s is not installed", e.Label)
388+
}
389+
382390
func (b *Sdk) Use(version Version, scope UseScope) error {
383391
logger.Debugf("Use SDK version: %s, scope:%v\n", string(version), scope)
384392

@@ -389,7 +397,9 @@ func (b *Sdk) Use(version Version, scope UseScope) error {
389397

390398
label := b.label(version)
391399
if !b.CheckExists(version) {
392-
return fmt.Errorf("%s is not installed", label)
400+
return &VersionNotExistsError{
401+
Label: label,
402+
}
393403
}
394404

395405
if !env.IsHookEnv() {

0 commit comments

Comments
 (0)