Skip to content

fix(cli): exit non-zero when dataset, kernel, and model write commands fail - #1243

Merged
stevemessick merged 1 commit into
Kaggle:mainfrom
sridipbasu:fix/cli-write-errors-exit-code
Nov 12, 2026
Merged

stevemessick merged 1 commit into
Kaggle:mainfrom
sridipbasu:fix/cli-write-errors-exit-code

Conversation

@sridipbasu

Copy link
Copy Markdown
Collaborator

Summary

While looking at the kaggle datasets create flow, I found that the command exits with code 0 when the server rejects the request.

For example, creating a dataset with an invalid slug prints:

Dataset creation error: Slug can only contain alphanumeric or "-" characters

but the command still exits with code 0, so scripts and CI jobs treat the failure as a success.

The issue was that the *_cli wrappers print the server's error field instead of raising an error. The same pattern exists in 11 write commands:

  • datasets create, datasets version
  • kernels push (and its alias kernels update)
  • models create, models update, models delete
  • models instances create, models instances update, models instances delete
  • models instances versions create, models instances versions delete

Users have reported these error messages in #255, #416 and #321. Those failures come from the server, so this PR does not resolve them, but with this change such failures are no longer reported as successful.

Fix

I updated the 11 CLI wrappers to raise a ValueError with the same message instead of printing it. This uses the existing error handling in main(), so the CLI now prints the error to stderr and exits with code 1. This follows the same approach as #1215.

The Python library methods (dataset_create_new(), kernels_push(), model_create_new(), etc.) remain unchanged and still return the response with its error field.

Warnings for partial success, such as invalid tags or data sources on kernels push, are unchanged and still exit with code 0.

Tests

Added tests/unit/test_cli_write_errors.py, which checks that each of the 11 wrappers raises a ValueError containing the server error.

All 11 subtests fail with the old implementation and pass with this fix.

Ran:

pytest tests/unit/test_cli_write_errors.py
pytest tests/unit

Results:

1 passed, 11 subtests passed
1454 passed, 1 warning, 59 subtests passed

Also ran the Black check, which passed.

I also verified this against the live API with kaggle datasets create using an invalid slug. The command now prints the error to stderr and exits with code 1 instead of 0. No dataset was created.

This change is limited to CLI error handling. It does not modify the Python library API, the API requests, or any waiting and polling flow.

@sridipbasu sridipbasu self-assigned this Nov 12, 2026
@sridipbasu sridipbasu added the bug Something isn't working label Nov 12, 2026

@stevemessick stevemessick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see more consistency.

@stevemessick
stevemessick merged commit e3583ad into Kaggle:main Nov 12, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants