Skip to content

Propagate errors when probing for generated schemas - #303

Merged
haarchri merged 1 commit into
crossplane:mainfrom
stevendborrelli:fix-swallowed-direxists-errors
Aug 30, 2026
Merged

Propagate errors when probing for generated schemas#303
haarchri merged 1 commit into
crossplane:mainfrom
stevendborrelli:fix-swallowed-direxists-errors

Conversation

@stevendborrelli

@stevendborrelli stevendborrelli commented Aug 29, 2026

Copy link
Copy Markdown
Member

Description of your changes

Four probes for a generated schemas directory discarded their error and treated the failure as "no schemas". An unreadable schemas directory therefore produced a silently degraded result instead of an error:

Location Silent failure
generatePythonFiles Scaffolds a function without the local schema dependency
generateGoFiles Omits the dev.crossplane.io/models replace directive
generateGoTemplatingFiles Omits the model index path
pythonBuilder.buildVenv Builds an image without the project's python schemas

In each case the user sees the real fault much later and in a misleading form — generated code that doesn't compile, or a function image missing its models — with nothing pointing at the schemas directory.

afero.DirExists and afero.Exists already report a missing directory as (false, nil), so a non-nil error here is a genuine I/O or permission fault and is worth surfacing rather than discarding.

Found while reviewing feedback on #170, which flags the same pattern in the TypeScript paths that PR introduces. Those instances live in code that only exists on that branch, so they're fixed there; this PR covers the pre-existing ones on main.

Deliberately not changed

internal/schemas/generator/python.go:769 uses the same if exists, _ := afero.Exists(...) shape when creating __init__.py files, but the error is not truly lost there: a failing probe falls through to afero.WriteFile, which reports its own wrapped error. Happy to include it if a reviewer would rather have it consistent.

I have:

Need help with this checklist? See the cheat sheet.

🤖 Generated with Claude Code

Four checks for a generated schemas directory discarded their error and
treated the failure as "no schemas". An unreadable or otherwise failing
schemas directory therefore produced a silently degraded result rather
than an error:

- generatePythonFiles and generateGoFiles scaffold a function without
  the local schema dependency, so the generated code fails to compile
  later for a reason unrelated to the real fault.
- generateGoTemplatingFiles omits the model index path.
- pythonBuilder.buildVenv builds an image without the project's python
  schemas.

afero.DirExists and afero.Exists already report a missing directory as
(false, nil), so a non-nil error here is a genuine I/O or permission
fault and is worth surfacing.

Signed-off-by: Steven Borrelli <steve@borrelli.org>

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@stevendborrelli
stevendborrelli requested review from bobh66 and removed request for a team August 29, 2026 16:43
@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b2c36a88-71a5-44b9-9b2e-cbf5962bd642

📥 Commits

Reviewing files that changed from the base of the PR and between 3d72f93 and ad553f9.

📒 Files selected for processing (2)
  • cmd/crossplane/function/generate.go
  • internal/project/functions/python.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Schema filesystem checks now propagate errors with contextual messages during function file generation and Python virtual-environment setup.

Changes

Schema error propagation

Layer / File(s) Summary
Generation schema checks
cmd/crossplane/function/generate.go
Python, Go, and Go templating generation now return wrapped errors when schema directory or index checks fail.
Python environment schema check
internal/project/functions/python.go
buildVenv now returns a wrapped error when checking the Python schemas directory fails.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to ad553

The change makes schema-directory I/O failures surface immediately instead of silently generating incomplete artifacts. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: bobh66


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Breaking Changes ❌ Error cmd/crossplane/function/generate.go removes existing behavior without a breaking-change label. Before this change, a schema probe error was ignored and the command generated files without the sche… Add the breaking-change label to the pull request. Alternatively, preserve the previous fallback behavior if this change is not intended to be treated as breaking.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is descriptive, directly related to the error-propagation changes, and is under 72 characters at 51 characters.
Description check ✅ Passed The description clearly explains the affected schema probes, the previous silent failures, the new error behavior, validation performed, and the deliberate scope.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Feature Gate Requirement ✅ Passed PASS. The pull request introduces no new experimental feature. The verified commit changes only cmd/crossplane/function/generate.go and internal/project/functions/python.go; no files under `apis/*…
Full details: Breaking Changes

Explanation

cmd/crossplane/function/generate.go removes existing behavior without a breaking-change label. Before this change, a schema probe error was ignored and the command generated files without the schema dependency or model path. The new code returns the probe error, and Run stops at the generator error path before writing files. The diff does not remove or rename public fields or flags and adds no required public fields or flags, but this is still a behavior removal under the check's explicit condition. No breaking-change marker appears in the commit metadata or description.

Full details: Feature Gate Requirement

Explanation

PASS. The pull request introduces no new experimental feature. The verified commit changes only cmd/crossplane/function/generate.go and internal/project/functions/python.go; no files under apis/** changed. The four added branches only return existing filesystem probe errors instead of treating probe failures as missing schemas. This is corrective error handling, not an experimental feature that requires a feature flag.

  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@haarchri
haarchri merged commit a2395b9 into crossplane:main Aug 30, 2026
10 of 11 checks passed
stevendborrelli added a commit to stevendborrelli/cli that referenced this pull request Aug 30, 2026
Integration fix. crossplane#304 adds a cacheDir parameter to baseImageForArch;
crossplane#170 adds a TypeScript builder that calls it. The branches merge cleanly
because they touch different files, but the result does not compile
without this. Whichever PR merges second upstream needs this one line.

Also update the testing notes: crossplane#302 and crossplane#303 have merged, so they now
arrive through main rather than as merges here.

Signed-off-by: Steven Borrelli <steve@borrelli.org>

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
stevendborrelli added a commit to stevendborrelli/cli that referenced this pull request Aug 30, 2026
The opening still said the branch merges four open PRs when only two
remain open. Reword it so the count does not go stale again, mark the
--no-default-mrap check as testing something that now lives in main, and
add a short section recording what has already landed.

Signed-off-by: Steven Borrelli <steve@borrelli.org>

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants