Skip to content

Commit 4832d1e

Browse files
cgrindelclaudemergify[bot]
authored
feat: improve error messages and code quality across Swift package tooling (#1720)
## Summary This PR improves error messages and code quality across the Swift package tooling ecosystem with several focused enhancements: - **Enhanced error messages**: Better contextual information for debugging Swift package configuration issues - **Security improvement**: More secure file permissions for dependency index files - **Code quality**: Fix CLI description typo and enable Claude Code Review workflow - **CI optimization**: Skip automated dependency update PRs from code review ## Changes ### 1. Enhanced Error Messages (`swiftpkg/internal/`) - **Target lookup errors**: Show available target names/labels when lookups fail - **Build declaration errors**: Show available declaration names when not found - **Duplicate detection**: Show conflicting declaration types for duplicates - **Git configuration errors**: Show what was provided vs what's required These improvements help developers quickly identify typos and understand available options when debugging Swift package configuration issues. ### 2. Security Improvement (`tools/swift_deps_index/cmd/create.go`) Changed file permissions for dependency index files from `0666` (world-writable) to `0644` (owner-writable, group/others read-only) following security best practices. ### 3. Code Quality Fixes - **CLI description**: Fixed typo "dependences" → "dependencies" in `swift_deps_index` tool - **CI workflow**: Enabled Claude Code Review workflow and excluded Renovate PRs to reduce noise ## Test Plan - [x] All tests pass: `bazel test //...` (327 tests passed) - [x] Changes are backwards compatible - [x] Error message improvements verified through existing test coverage - [x] Security change maintains functionality while improving permissions 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 4fffc88 commit 4832d1e

File tree

6 files changed

+47
-23
lines changed

6 files changed

+47
-23
lines changed

.github/workflows/claude-code-review.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
name: Claude Code Review
22

3-
# on:
4-
# pull_request:
5-
# types: [opened, synchronize]
6-
# # Optional: Only run on specific file changes
7-
# # paths:
8-
# # - "src/**/*.ts"
9-
# # - "src/**/*.tsx"
10-
# # - "src/**/*.js"
11-
# # - "src/**/*.jsx"
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
# Optional: Only run on specific file changes
7+
# paths:
8+
# - "src/**/*.ts"
9+
# - "src/**/*.tsx"
10+
# - "src/**/*.js"
11+
# - "src/**/*.jsx"
1212

1313
jobs:
1414
claude-review:
15-
# Skip draft PRs
16-
if: github.event.pull_request.draft == false
15+
# Skip draft PRs and Renovate PRs
16+
if: github.event.pull_request.draft == false && github.event.pull_request.user.login != 'app/cgrindel-self-hosted-renovate'
1717

1818
# Optional: Filter by PR author
1919
# if: |

swiftpkg/internal/build_decls.bzl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ def _uniq(decls):
7575
for decl in results:
7676
name = decl.name
7777
if sets.contains(names, name):
78-
fail("A duplicate decl name was found. name: {}".format(name))
78+
existing_decls = [d for d in results if d.name == name]
79+
fail("Duplicate declaration name '{}' found. Declaration types: [{}]".format(
80+
name,
81+
", ".join([d.kind for d in existing_decls]),
82+
))
7983
sets.insert(names, name)
8084

8185
return results
@@ -97,7 +101,11 @@ def _get(decls, name, fail_if_not_found = True):
97101
if decl.name == name:
98102
return decl
99103
if fail_if_not_found:
100-
fail("Failed to find build declaration. name:", name)
104+
available_names = [d.name for d in decls if d.name]
105+
fail("Failed to find build declaration '{}'. Available declarations: [{}]".format(
106+
name,
107+
", ".join(available_names),
108+
))
101109
return None
102110

103111
build_decls = struct(

swiftpkg/internal/pkginfo_targets.bzl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ def _get(targets, name, fail_if_not_found = True):
2929
if target.name == name:
3030
return target
3131
if fail_if_not_found:
32-
fail("Failed to find target. name:", name)
32+
available_names = [t.name for t in targets]
33+
fail("Failed to find target '{}'. Available targets: [{}]".format(
34+
name,
35+
", ".join(available_names),
36+
))
3337
return None
3438

3539
def _get_by_label(targets, label, fail_if_not_found = True):
@@ -50,7 +54,11 @@ def _get_by_label(targets, label, fail_if_not_found = True):
5054
if target.label == label:
5155
return target
5256
if fail_if_not_found:
53-
fail("Failed to find target. label:", label)
57+
available_labels = [t.label for t in targets]
58+
fail("Failed to find target with label '{}'. Available target labels: [{}]".format(
59+
label,
60+
", ".join(available_labels),
61+
))
5462
return None
5563

5664
def _srcs(target):

swiftpkg/internal/swift_package.bzl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@ load(":repo_rules.bzl", "repo_rules")
1616
# MARK: - Environment Variables
1717

1818
def _clone_or_update_repo(repository_ctx, directory):
19-
if ((not repository_ctx.attr.tag and not repository_ctx.attr.commit and not repository_ctx.attr.branch) or
20-
(repository_ctx.attr.tag and repository_ctx.attr.commit) or
21-
(repository_ctx.attr.tag and repository_ctx.attr.branch) or
22-
(repository_ctx.attr.commit and repository_ctx.attr.branch)):
23-
fail("Exactly one of commit, tag, or branch must be provided")
19+
# Validate that exactly one of commit, tag, or branch is provided
20+
provided = []
21+
if repository_ctx.attr.commit:
22+
provided.append("commit")
23+
if repository_ctx.attr.tag:
24+
provided.append("tag")
25+
if repository_ctx.attr.branch:
26+
provided.append("branch")
27+
28+
if len(provided) != 1:
29+
fail("Exactly one of commit, tag, or branch must be provided. Found: [{}]".format(
30+
", ".join(provided) if provided else "none",
31+
))
2432

2533
git_ = git_repo(repository_ctx, directory)
2634

tools/swift_deps_index/cmd/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/spf13/cobra"
1111
)
1212

13-
const dependencyIndexPerms = 0666
13+
const dependencyIndexPerms = 0644
1414

1515
var outputPath string
1616

tools/swift_deps_index/cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
// rootCmd represents the base command when called without any subcommands
1010
var rootCmd = &cobra.Command{
1111
Use: "swift_deps_index",
12-
Short: "Manage a Swift dependences index file.",
13-
Long: `Manage a Swift dependences index file.`,
12+
Short: "Manage a Swift dependencies index file.",
13+
Long: `Manage a Swift dependencies index file.`,
1414
}
1515

1616
// Execute adds all child commands to the root command and sets flags appropriately.

0 commit comments

Comments
 (0)