mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
fix: handle errors from ReconcileGlobalSkills, filepath.Walk, and remove redundant applyExclude
Address PR #29 review feedback: - Log warnings on ReconcileGlobalSkills/ReconcileProjectSkills failures instead of silently discarding errors - Propagate filepath.Walk callback errors in uninstall group/nested resolution - Remove redundant applyExclude call in selectSkills (callers already filter)
This commit is contained in:
+10
-19
@@ -319,7 +319,9 @@ func cmdInstall(args []string) error {
|
||||
summary.Source = parsed.sourceArg
|
||||
}
|
||||
if err == nil && !parsed.opts.DryRun && len(summary.InstalledSkills) > 0 {
|
||||
_ = config.ReconcileGlobalSkills(cfg)
|
||||
if rErr := config.ReconcileGlobalSkills(cfg); rErr != nil {
|
||||
ui.Warning("Failed to reconcile global skills config: %v", rErr)
|
||||
}
|
||||
}
|
||||
logInstallOp(config.ConfigPath(), rest, start, err, summary)
|
||||
return err
|
||||
@@ -333,7 +335,9 @@ func cmdInstall(args []string) error {
|
||||
summary.Source = parsed.sourceArg
|
||||
}
|
||||
if err == nil && !parsed.opts.DryRun && len(summary.InstalledSkills) > 0 {
|
||||
_ = config.ReconcileGlobalSkills(cfg)
|
||||
if rErr := config.ReconcileGlobalSkills(cfg); rErr != nil {
|
||||
ui.Warning("Failed to reconcile global skills config: %v", rErr)
|
||||
}
|
||||
}
|
||||
logInstallOp(config.ConfigPath(), rest, start, err, summary)
|
||||
return err
|
||||
@@ -627,11 +631,8 @@ func handleGitDiscovery(source *install.Source, cfg *config.Config, opts install
|
||||
|
||||
// selectSkills routes to the appropriate skill selection method:
|
||||
// --skill filter, --all/--yes auto-select, or interactive prompt.
|
||||
// After selection, applies --exclude filtering if specified.
|
||||
// Callers are expected to apply --exclude filtering before calling this function.
|
||||
func selectSkills(skills []install.SkillInfo, opts install.InstallOptions) ([]install.SkillInfo, error) {
|
||||
var selected []install.SkillInfo
|
||||
var err error
|
||||
|
||||
switch {
|
||||
case opts.HasSkillFilter():
|
||||
matched, notFound := filterSkillsByName(skills, opts.Skills)
|
||||
@@ -639,22 +640,12 @@ func selectSkills(skills []install.SkillInfo, opts install.InstallOptions) ([]in
|
||||
return nil, fmt.Errorf("skills not found: %s\nAvailable: %s",
|
||||
strings.Join(notFound, ", "), skillNames(skills))
|
||||
}
|
||||
selected = matched
|
||||
return matched, nil
|
||||
case opts.ShouldInstallAll():
|
||||
selected = skills
|
||||
return skills, nil
|
||||
default:
|
||||
selected, err = promptSkillSelection(skills)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return promptSkillSelection(skills)
|
||||
}
|
||||
|
||||
// Apply --exclude filter
|
||||
if len(opts.Exclude) > 0 {
|
||||
selected = applyExclude(selected, opts.Exclude)
|
||||
}
|
||||
|
||||
return selected, nil
|
||||
}
|
||||
|
||||
// applyExclude removes skills whose names appear in the exclude list.
|
||||
|
||||
@@ -425,6 +425,9 @@ func formatGenericLogPairs(args map[string]any) []logDetailPair {
|
||||
if name, ok := logArgString(args, "name"); ok {
|
||||
pairs = append(pairs, logDetailPair{key: "name", value: name})
|
||||
}
|
||||
if names, ok := logArgStringSlice(args, "names"); ok && len(names) > 0 {
|
||||
pairs = append(pairs, logDetailPair{key: "names", isList: true, listValues: names})
|
||||
}
|
||||
if target, ok := logArgString(args, "target"); ok {
|
||||
pairs = append(pairs, logDetailPair{key: "target", value: target})
|
||||
}
|
||||
@@ -679,6 +682,9 @@ func formatGenericLogDetail(args map[string]any) string {
|
||||
if name, ok := logArgString(args, "name"); ok {
|
||||
parts = append(parts, name)
|
||||
}
|
||||
if names, ok := logArgStringSlice(args, "names"); ok && len(names) > 0 {
|
||||
parts = append(parts, strings.Join(names, ", "))
|
||||
}
|
||||
if target, ok := logArgString(args, "target"); ok {
|
||||
parts = append(parts, target)
|
||||
}
|
||||
|
||||
@@ -626,7 +626,9 @@ func installFromSearchResult(result search.SearchResult, cfg *config.Config) (er
|
||||
logSummary.InstalledSkills = []string{result.Name}
|
||||
|
||||
// Reconcile global config with installed skills
|
||||
_ = config.ReconcileGlobalSkills(cfg)
|
||||
if rErr := config.ReconcileGlobalSkills(cfg); rErr != nil {
|
||||
ui.Warning("Failed to reconcile global skills config: %v", rErr)
|
||||
}
|
||||
|
||||
// Show warnings
|
||||
for _, warning := range installResult.Warnings {
|
||||
|
||||
@@ -113,8 +113,11 @@ func resolveGroupSkills(group, sourceDir string) ([]*uninstallTarget, error) {
|
||||
}
|
||||
|
||||
var targets []*uninstallTarget
|
||||
filepath.Walk(groupPath, func(path string, fi os.FileInfo, err error) error { //nolint:errcheck
|
||||
if err != nil || path == groupPath || !fi.IsDir() {
|
||||
if walkErr := filepath.Walk(groupPath, func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if path == groupPath || !fi.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if fi.Name() == ".git" {
|
||||
@@ -140,7 +143,9 @@ func resolveGroupSkills(group, sourceDir string) ([]*uninstallTarget, error) {
|
||||
return filepath.SkipDir // don't descend into skill dirs
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}); walkErr != nil {
|
||||
return nil, fmt.Errorf("failed to walk group '%s': %w", group, walkErr)
|
||||
}
|
||||
|
||||
if len(targets) == 0 {
|
||||
return nil, fmt.Errorf("no skills found in group '%s'", group)
|
||||
@@ -156,8 +161,11 @@ func resolveGroupSkills(group, sourceDir string) ([]*uninstallTarget, error) {
|
||||
func resolveNestedSkillDir(sourceDir, name string) (string, error) {
|
||||
var matches []string
|
||||
|
||||
filepath.Walk(sourceDir, func(path string, info os.FileInfo, err error) error { //nolint:errcheck
|
||||
if err != nil || path == sourceDir || !info.IsDir() {
|
||||
if walkErr := filepath.Walk(sourceDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if path == sourceDir || !info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if info.Name() == ".git" {
|
||||
@@ -170,7 +178,9 @@ func resolveNestedSkillDir(sourceDir, name string) (string, error) {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}); walkErr != nil {
|
||||
return "", fmt.Errorf("failed to search for skill '%s': %w", name, walkErr)
|
||||
}
|
||||
|
||||
switch len(matches) {
|
||||
case 0:
|
||||
@@ -191,8 +201,11 @@ func resolveNestedSkillDir(sourceDir, name string) (string, error) {
|
||||
// Returns the list of relative skill names found, or nil if not a group.
|
||||
func countGroupSkills(dir string) []string {
|
||||
var names []string
|
||||
filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error { //nolint:errcheck
|
||||
if err != nil || path == dir || !fi.IsDir() {
|
||||
_ = filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if path == dir || !fi.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if fi.Name() == ".git" {
|
||||
|
||||
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -192,9 +193,13 @@ func (s *Server) handleInstallBatch(w http.ResponseWriter, r *http.Request) {
|
||||
// Reconcile config after install
|
||||
if installed > 0 {
|
||||
if s.IsProjectMode() {
|
||||
_ = config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.cfg.Source)
|
||||
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.cfg.Source); rErr != nil {
|
||||
log.Printf("warning: failed to reconcile project skills config: %v", rErr)
|
||||
}
|
||||
} else {
|
||||
_ = config.ReconcileGlobalSkills(s.cfg)
|
||||
if rErr := config.ReconcileGlobalSkills(s.cfg); rErr != nil {
|
||||
log.Printf("warning: failed to reconcile global skills config: %v", rErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,9 +277,13 @@ func (s *Server) handleInstall(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
// Reconcile config after tracked repo install
|
||||
if s.IsProjectMode() {
|
||||
_ = config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.cfg.Source)
|
||||
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.cfg.Source); rErr != nil {
|
||||
log.Printf("warning: failed to reconcile project skills config: %v", rErr)
|
||||
}
|
||||
} else {
|
||||
_ = config.ReconcileGlobalSkills(s.cfg)
|
||||
if rErr := config.ReconcileGlobalSkills(s.cfg); rErr != nil {
|
||||
log.Printf("warning: failed to reconcile global skills config: %v", rErr)
|
||||
}
|
||||
}
|
||||
|
||||
args := map[string]any{
|
||||
@@ -343,9 +352,13 @@ func (s *Server) handleInstall(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Reconcile config after single install
|
||||
if s.IsProjectMode() {
|
||||
_ = config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.cfg.Source)
|
||||
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.cfg.Source); rErr != nil {
|
||||
log.Printf("warning: failed to reconcile project skills config: %v", rErr)
|
||||
}
|
||||
} else {
|
||||
_ = config.ReconcileGlobalSkills(s.cfg)
|
||||
if rErr := config.ReconcileGlobalSkills(s.cfg); rErr != nil {
|
||||
log.Printf("warning: failed to reconcile global skills config: %v", rErr)
|
||||
}
|
||||
}
|
||||
|
||||
okArgs := map[string]any{
|
||||
|
||||
Reference in New Issue
Block a user