Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ title: Changelog
* `[Fixed]` Resolve `go to definition` from command references such as `ref: build` to the referenced command in `lets self lsp`.
* `[Added]` Load local mixin files into LSP storage and command index so mixin commands are available for navigation.
* `[Changed]` Replace the top-level `--upgrade` flag with the `lets self upgrade` command.
* `[Fixed]` Return a normal parse error when a local mixin contains malformed YAML instead of crashing.

## [0.0.59](https://github.com/lets-cli/lets/releases/tag/v0.0.59)

Expand Down
2 changes: 1 addition & 1 deletion internal/config/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (c *Config) readMixins(mixins []*Mixin) error {

for _, mixin := range mixins {
if err := c.readMixin(mixin); err != nil {
return fmt.Errorf("failed to read remote mixin config '%s': %w", mixin.Remote.URL, err)
return fmt.Errorf("failed to read mixin config '%s': %w", mixin.Source(), err)
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/config/config/mixin.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,11 @@ func (m *Mixin) UnmarshalYAML(unmarshal func(any) error) error {
func (m *Mixin) IsRemote() bool {
return m.Remote != nil
}

func (m *Mixin) Source() string {
if m.IsRemote() {
return m.Remote.URL
}

return m.FileName
}
30 changes: 30 additions & 0 deletions internal/config/load_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import (
"os"
"path/filepath"
"strings"
"testing"
)

Expand All @@ -11,4 +14,31 @@ func TestLoadConfig(t *testing.T) {
t.Errorf("can not load test config: %s", err)
}
})

t.Run("returns error for malformed local mixin", func(t *testing.T) {
tempDir := t.TempDir()

mainConfig := "shell: bash\nmixins: [mixin.yaml]\ncommands:\n ok:\n cmd: echo ok\n"
if err := os.WriteFile(filepath.Join(tempDir, "lets.yaml"), []byte(mainConfig), 0o644); err != nil {
t.Fatalf("write main config: %v", err)
}

mixinConfig := "commands:\n test1:\n xxx\n cmd: echo Test\n"
if err := os.WriteFile(filepath.Join(tempDir, "mixin.yaml"), []byte(mixinConfig), 0o644); err != nil {
t.Fatalf("write mixin config: %v", err)
}

_, err := Load("", tempDir, "0.0.0-test")
if err == nil {
t.Fatal("expected malformed mixin error")
}

if !strings.Contains(err.Error(), "failed to read mixin config 'mixin.yaml'") {
t.Fatalf("unexpected error: %v", err)
}

if !strings.Contains(err.Error(), "can not parse mixin config mixin.yaml") {
t.Fatalf("unexpected error: %v", err)
}
})
}
Loading