Skip to content

fix: include model name in duplicate-property error message#10196

Merged
baywet merged 3 commits intomainfrom
copilot/fix-duplicate-property-error-message
Mar 30, 2026
Merged

fix: include model name in duplicate-property error message#10196
baywet merged 3 commits intomainfrom
copilot/fix-duplicate-property-error-message

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

fixes #10195
fixes #877

The duplicate-property diagnostic omitted the model name, making it harder to locate the offending model in large specs.

Changes

  • messages.ts: Added withModel message variant to duplicate-property: Model ${"modelName"} already has a property named ${"propName"}
  • checker.ts: defineProperty now selects withModel when newProp.model?.name is non-empty, falling back to the original default message for anonymous model expressions
  • Tests: Updated assertions in model.test.ts and check-parse-errors.test.ts to match the new format

Before / After

// Before
error duplicate-property: Model already has a property named id

// After
error duplicate-property: Model Foo already has a property named id

Anonymous model expressions (no name) retain the original message.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Mar 30, 2026
Copilot AI changed the title [WIP] Fix duplicate-property error message to include model name fix: include model name in duplicate-property error message Mar 30, 2026
Copilot AI requested a review from baywet March 30, 2026 13:49
@baywet baywet marked this pull request as ready for review March 30, 2026 13:56
@baywet baywet enabled auto-merge March 30, 2026 13:56
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 30, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@10196

commit: 0350802

Copy link
Copy Markdown
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

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

ok to have that but I think what we really missing is where is that original property coming from which I think is often the source of confusion here(from a spread or model is).
Also should close #877(dup issue)

@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@baywet baywet added this pull request to the merge queue Mar 30, 2026
Merged via the queue into main with commit 30ad243 Mar 30, 2026
40 checks passed
@baywet baywet deleted the copilot/fix-duplicate-property-error-message branch March 30, 2026 14:47
msyyc pushed a commit that referenced this pull request Apr 1, 2026
fixes #10195
fixes #877

The `duplicate-property` diagnostic omitted the model name, making it
harder to locate the offending model in large specs.

## Changes

- **`messages.ts`**: Added `withModel` message variant to
`duplicate-property`: `Model ${"modelName"} already has a property named
${"propName"}`
- **`checker.ts`**: `defineProperty` now selects `withModel` when
`newProp.model?.name` is non-empty, falling back to the original
`default` message for anonymous model expressions
- **Tests**: Updated assertions in `model.test.ts` and
`check-parse-errors.test.ts` to match the new format

## Before / After

```
// Before
error duplicate-property: Model already has a property named id

// After
error duplicate-property: Model Foo already has a property named id
```

Anonymous model expressions (no name) retain the original message.

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: baywet <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

duplicate-property error message should provide the model name Duplicate property error message should include the name of the model.

4 participants