Skip to content

refactor(api): type the add errors - #7416

Merged
Hofer-Julian merged 3 commits into
prefix-dev:mainfrom
lucascolley:type-pixi-api-add-errors
Nov 2, 2026
Merged

Hofer-Julian merged 3 commits into
prefix-dev:mainfrom
lucascolley:type-pixi-api-add-errors

Conversation

@lucascolley

Copy link
Copy Markdown
Member

Part of #6707. This types add_conda_deps and add_pypi_deps, and aligns the remove error with the conventions used since.

Both now save the manifest through the shared error that names it, and report a failure to restore the manifest after a failed update the same way. The remove error's lock file variant is no longer boxed, so its source can be downcast again. resolve_platforms now returns the manifest's typed "platform not found" error, which has the same message.

Two fixes, each in its own commit:

  • When adding dependencies failed and restoring the manifest then failed too, only the restore error was reported. The restore error now carries the original error as a related diagnostic.
  • WorkspaceMut::revert always rewrote the manifest, even when the changes were never saved, unlike dropping a WorkspaceMut. With a read-only pixi.toml, a failed pixi add reported that it could not restore the manifest instead of why the add failed (e.g. writing the lock file).
Before After
dependency `{name}` was not found dependency '{name}' was not found
Cannot remove Python while PyPI dependencies exist. Please remove these PyPI dependencies first: {deps} cannot remove 'python' while PyPI dependencies exist, with help Remove these PyPI dependencies first: {deps}.
failed to save the manifest, caused by {io error} failed to save '{manifest}', caused by {io error}
{io error} failed to save '{manifest}', caused by {io error}
{io error} failed to restore '{manifest}', caused by {io error}

Part of prefix-dev#6707. This types `add_conda_deps` and `add_pypi_deps`, and
aligns the remove error with the conventions used since.

Both now save the manifest through the shared error that names it, and
report a failure to restore the manifest after a failed update the
same way. The remove error's lock file variant is no longer boxed, so
its source can be downcast again.

`resolve_platforms` now returns the manifest's typed "platform not
found" error, which has the same message.

| Before | After |
|---|---|
| ``dependency `{name}` was not found`` | dependency '{name}' was not found |
| Cannot remove Python while PyPI dependencies exist. Please remove these PyPI dependencies first: {deps} | cannot remove 'python' while PyPI dependencies exist, with help Remove these PyPI dependencies first: {deps}. |
| failed to save the manifest, caused by {io error} | failed to save '{manifest}', caused by {io error} |
| {io error} | failed to save '{manifest}', caused by {io error} |
| {io error} | failed to restore '{manifest}', caused by {io error} |
Part of prefix-dev#6707. When adding dependencies failed and restoring the
manifest then failed too, only the restore error was reported. With a
read-only workspace directory, `pixi add` reported that it could not
write `pixi.toml`, but not that writing the lock file had failed first.
The restore error now carries the original error as a related
diagnostic.
Part of prefix-dev#6707. `WorkspaceMut::revert` always rewrote the manifest, even
when the changes were never saved, unlike dropping a `WorkspaceMut`.
With a read-only `pixi.toml`, a failed `pixi add` then reported that it
could not restore the manifest instead of why the add failed.
@lucascolley
lucascolley force-pushed the type-pixi-api-add-errors branch from aaa4871 to c2a2774 Compare October 30, 2026 16:41

@Hofer-Julian Hofer-Julian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

@Hofer-Julian
Hofer-Julian merged commit 740e317 into prefix-dev:main Nov 2, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants