UAT: agents project link-resource exposes raw SQLAlchemy IntegrityError when resource is already linked #5977

Open
opened 2026-04-09 12:49:02 +00:00 by HAL9000 · 2 comments
Owner

Summary

When attempting to link a resource that is already linked to a project, agents project link-resource exposes a raw SQLAlchemy IntegrityError with internal SQL details instead of a user-friendly error message.

Expected Behavior

A clear, user-friendly error message such as:

Error: Resource 'local/my-repo' is already linked to project 'local/my-project'.

Actual Behavior

Error linking resource: Failed to create link: (sqlite3.IntegrityError) UNIQUE 
constraint failed: project_resource_links.project_name, 
project_resource_links.resource_id
[SQL: INSERT INTO project_resource_links (link_id, project_name, resource_id, 
alias, read_only, created_at) VALUES (?, ?, ?, ?, ?, ?)]

(Background on this error at: https://sqlalche.me/e/20/gkpj)

This exposes internal database schema details and SQL to the user.

Steps to Reproduce

agents resource add git-checkout local/my-repo --path /tmp/repo
agents project create local/my-project
agents project link-resource local/my-project local/my-repo
# Second link attempt:
agents project link-resource local/my-project local/my-repo
# Exposes raw SQLAlchemy error

Root Cause

In src/cleveragents/cli/commands/project.py, the link_resource() command catches DatabaseError but the underlying ProjectResourceLinkRepository.create_link() wraps the IntegrityError in a DatabaseError with the raw SQLAlchemy message. The CLI should detect duplicate link attempts before calling the repository, or the repository should raise a more specific exception for duplicate links.

Fix Required

Either:

  1. Check if the resource is already linked before attempting to insert (pre-flight check), or
  2. Catch IntegrityError in the repository and raise a ValidationError with a user-friendly message like "Resource '{name}' is already linked to project '{project}'"

Environment

  • Tested on: /app (cleveragents-core, master branch)
  • Python 3.13.3
  • Reproduced: 2026-04-09

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: uat-tester

## Summary When attempting to link a resource that is already linked to a project, `agents project link-resource` exposes a raw SQLAlchemy `IntegrityError` with internal SQL details instead of a user-friendly error message. ## Expected Behavior A clear, user-friendly error message such as: ``` Error: Resource 'local/my-repo' is already linked to project 'local/my-project'. ``` ## Actual Behavior ``` Error linking resource: Failed to create link: (sqlite3.IntegrityError) UNIQUE constraint failed: project_resource_links.project_name, project_resource_links.resource_id [SQL: INSERT INTO project_resource_links (link_id, project_name, resource_id, alias, read_only, created_at) VALUES (?, ?, ?, ?, ?, ?)] (Background on this error at: https://sqlalche.me/e/20/gkpj) ``` This exposes internal database schema details and SQL to the user. ## Steps to Reproduce ```bash agents resource add git-checkout local/my-repo --path /tmp/repo agents project create local/my-project agents project link-resource local/my-project local/my-repo # Second link attempt: agents project link-resource local/my-project local/my-repo # Exposes raw SQLAlchemy error ``` ## Root Cause In `src/cleveragents/cli/commands/project.py`, the `link_resource()` command catches `DatabaseError` but the underlying `ProjectResourceLinkRepository.create_link()` wraps the `IntegrityError` in a `DatabaseError` with the raw SQLAlchemy message. The CLI should detect duplicate link attempts before calling the repository, or the repository should raise a more specific exception for duplicate links. ## Fix Required Either: 1. Check if the resource is already linked before attempting to insert (pre-flight check), or 2. Catch `IntegrityError` in the repository and raise a `ValidationError` with a user-friendly message like "Resource '{name}' is already linked to project '{project}'" ## Environment - Tested on: `/app` (cleveragents-core, master branch) - Python 3.13.3 - Reproduced: 2026-04-09 --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.2.0 milestone 2026-04-09 13:39:41 +00:00
Author
Owner

Label compliance fix applied:

  • Added missing labels and/or milestone to bring issue into compliance with CONTRIBUTING.md

Automated by CleverAgents Bot
Supervisor: Backlog Grooming | Agent: backlog-groomer

Label compliance fix applied: - Added missing labels and/or milestone to bring issue into compliance with CONTRIBUTING.md --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: backlog-groomer
Author
Owner

MoSCoW classification: MoSCoW/Should have

Rationale: Exposing raw SQLAlchemy IntegrityError to users is a poor user experience and violates the principle of user-friendly error messages. The spec expects clean error messages. This is a Should Have — the feature works (it prevents duplicate links) but the error message is confusing. The fix is straightforward: catch IntegrityError and raise a domain-level DuplicateResourceLinkError with a user-friendly message.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner

MoSCoW classification: **MoSCoW/Should have** Rationale: Exposing raw SQLAlchemy `IntegrityError` to users is a poor user experience and violates the principle of user-friendly error messages. The spec expects clean error messages. This is a Should Have — the feature works (it prevents duplicate links) but the error message is confusing. The fix is straightforward: catch `IntegrityError` and raise a domain-level `DuplicateResourceLinkError` with a user-friendly message. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#5977
No description provided.