Skip to content

fix(config): prevent silent success on empty configs and fix context switch error propagation#930

Open
gcharpe1604 wants to merge 1 commit into
goharbor:mainfrom
gcharpe1604:fix/config-context-error-handling
Open

fix(config): prevent silent success on empty configs and fix context switch error propagation#930
gcharpe1604 wants to merge 1 commit into
goharbor:mainfrom
gcharpe1604:fix/config-context-error-handling

Conversation

@gcharpe1604
Copy link
Copy Markdown
Contributor

Description

This PR addresses ungraceful handling of empty configuration files and context switching errors. Previously, applying an empty configuration resulted in a silent success (exit 0), and failing to switch contexts printed an error but still exited gracefully, which breaks automation scripts.

Type of Change

Please select the relevant type.

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • Added nil checks in cmd/harbor/root/configurations/apply.go to error out on empty configuration files instead of silently succeeding.
  • Refactored cmd/harbor/root/context/switch.go to return an explicit error, allowing Cobra to emit a proper non-zero exit code (exit 1) on failure.

- Added validation in \harbor config apply\ to prevent silently accepting empty or invalid configuration files.

- Updated \harbor context switch\ to return a non-zero exit code and standard error format when a context is not found, improving scriptability and automation UX.

Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 8.51%. Comparing base (60ad0bd) to head (337a347).
⚠️ Report is 162 commits behind head on main.

Files with missing lines Patch % Lines
cmd/harbor/root/configurations/apply.go 0.00% 2 Missing ⚠️
cmd/harbor/root/context/switch.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #930      +/-   ##
=========================================
- Coverage   10.99%   8.51%   -2.48%     
=========================================
  Files         173     288     +115     
  Lines        8671   14445    +5774     
=========================================
+ Hits          953    1230     +277     
- Misses       7612   13098    +5486     
- Partials      106     117      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[bug]: Silent success on empty configurations and improper context switch error propagation

1 participant