Skip to content

Commit 1b8c89e

Browse files
refactor(cli): Move exit code integers into named constants
- Add EXIT_SUCCESS, EXIT_FIXABLE_VIA_MIGRATION, EXIT_NON_FIXABLE_ISSUES, EXIT_GENERAL_ERROR constants - Replace all hardcoded exit code integers with named constants throughout the file - Addresses Aaron's GitHub comment about moving exit code integers to constants - Functionality remains identical - pure refactoring for readability Co-Authored-By: AJ Steers <[email protected]>
1 parent dd4636f commit 1b8c89e

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

airbyte_cdk/cli/airbyte_cdk/_manifest.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
_get_declarative_component_schema,
2222
)
2323

24+
EXIT_SUCCESS = 0
25+
EXIT_FIXABLE_VIA_MIGRATION = 1
26+
EXIT_NON_FIXABLE_ISSUES = 2
27+
EXIT_GENERAL_ERROR = 3
28+
2429

2530
@click.group(
2631
name="manifest",
@@ -64,7 +69,7 @@ def validate_manifest(manifest_path: Path, strict: bool) -> None:
6469
f"❌ Error: Manifest file {manifest_path} does not contain a valid YAML dictionary",
6570
err=True,
6671
)
67-
sys.exit(3)
72+
sys.exit(EXIT_GENERAL_ERROR)
6873

6974
schema = _get_declarative_component_schema()
7075

@@ -97,7 +102,7 @@ def validate_manifest(manifest_path: Path, strict: bool) -> None:
97102
click.echo(
98103
"Run 'airbyte-cdk manifest migrate' to apply available migrations.", err=True
99104
)
100-
sys.exit(1) # Fixable via migration
105+
sys.exit(EXIT_FIXABLE_VIA_MIGRATION)
101106

102107
if migration_available:
103108
try:
@@ -109,27 +114,27 @@ def validate_manifest(manifest_path: Path, strict: bool) -> None:
109114
"✅ Issues are fixable via migration. Run 'airbyte-cdk manifest migrate' to fix these issues.",
110115
err=True,
111116
)
112-
sys.exit(1) # Fixable via migration
117+
sys.exit(EXIT_FIXABLE_VIA_MIGRATION)
113118
except ValidationError:
114119
click.echo(f"❌ Validation failed for {manifest_path}:", err=True)
115120
if validation_error:
116121
click.echo(f" {validation_error.message}", err=True)
117-
sys.exit(2) # Non-fixable issues
122+
sys.exit(EXIT_NON_FIXABLE_ISSUES)
118123
else:
119124
click.echo(f"❌ Validation failed for {manifest_path}:", err=True)
120125
if validation_error:
121126
click.echo(f" {validation_error.message}", err=True)
122-
sys.exit(2) # Non-fixable issues
127+
sys.exit(EXIT_NON_FIXABLE_ISSUES)
123128

124129
except FileNotFoundError:
125130
click.echo(f"❌ Error: Manifest file {manifest_path} not found", err=True)
126-
sys.exit(3)
131+
sys.exit(EXIT_GENERAL_ERROR)
127132
except yaml.YAMLError as e:
128133
click.echo(f"❌ Error: Invalid YAML in {manifest_path}: {e}", err=True)
129-
sys.exit(3)
134+
sys.exit(EXIT_GENERAL_ERROR)
130135
except Exception as e:
131136
click.echo(f"❌ Unexpected error validating {manifest_path}: {e}", err=True)
132-
sys.exit(3)
137+
sys.exit(EXIT_GENERAL_ERROR)
133138

134139

135140
@manifest_cli_group.command("migrate")
@@ -158,7 +163,7 @@ def migrate_manifest(manifest_path: Path, dry_run: bool) -> None:
158163
f"❌ Error: Manifest file {manifest_path} does not contain a valid YAML dictionary",
159164
err=True,
160165
)
161-
sys.exit(3)
166+
sys.exit(EXIT_GENERAL_ERROR)
162167

163168
migration_handler = ManifestMigrationHandler(original_manifest)
164169
migrated_manifest = migration_handler.apply_migrations()
@@ -198,13 +203,13 @@ def migrate_manifest(manifest_path: Path, dry_run: bool) -> None:
198203

199204
except FileNotFoundError:
200205
click.echo(f"❌ Error: Manifest file {manifest_path} not found", err=True)
201-
sys.exit(3)
206+
sys.exit(EXIT_GENERAL_ERROR)
202207
except yaml.YAMLError as e:
203208
click.echo(f"❌ Error: Invalid YAML in {manifest_path}: {e}", err=True)
204-
sys.exit(3)
209+
sys.exit(EXIT_GENERAL_ERROR)
205210
except Exception as e:
206211
click.echo(f"❌ Unexpected error migrating {manifest_path}: {e}", err=True)
207-
sys.exit(1)
212+
sys.exit(EXIT_FIXABLE_VIA_MIGRATION)
208213

209214

210215
__all__ = [

0 commit comments

Comments
 (0)