Skip to content

Deprecate @raises in favor of @throws in reanalyze - #7932

Merged
tsnobip merged 10 commits into
masterfrom
copilot/fix-ffd931b9-0aba-4a57-b568-72a4365d3180
Oct 3, 2025
Merged

tsnobip merged 10 commits into
masterfrom
copilot/fix-ffd931b9-0aba-4a57-b568-72a4365d3180

Conversation

Copilot AI commented Oct 2, 2025 •

Copy link
Copy Markdown
Contributor

Overview

This PR deprecates the @raises decorator in reanalyze in favor of @throws to better align with JavaScript and ReScript terminology. The change maintains full backward compatibility while guiding users toward the new decorator.

Motivation

ReScript uses throw for raising exceptions (not raise), so using @throws for the exception analysis decorator provides better consistency with the language's terminology and makes it more intuitive for developers.

Changes

Core Reanalyze

  • Exception.ml: Updated to accept both @throws/@throw (new) and @raises/@raise (deprecated) decorators
  • Log_.ml: Updated warning messages to suggest @throws instead of @raises

Example warning message before:

myFunction might raise Not_found and is not annotated with @raises(Not_found)

Example warning message after:

myFunction might raise Not_found and is not annotated with @throws(Not_found)

IDE/Editor Support

  • CompletionDecorators.ml: Added @throws decorator with full documentation and marked @raises as deprecated with a clear migration message

Documentation & Examples

  • Updated all test files to use @throws decorator
  • Updated expected test outputs to reflect new terminology
  • Updated Stdlib_JSON runtime library to use @throws

Backward Compatibility

✅ No breaking changes. Existing code using @raises will continue to work without modification. The implementation accepts all variants:

// NEW - Recommended
@throws(MyException)
let myFunction = () => throw(MyException)

// OLD - Still works but deprecated
@raises(MyException)
let myFunction = () => throw(MyException)

IDE users will see a deprecation notice when using @raises, guiding them to use @throws instead, but their code will function identically.

Migration

Users can migrate at their own pace. Simply replace @raises with @throws:

-@raises(Not_found)
+@throws(Not_found)
 let findValue = key => Dict.getExn(myDict, key)

Both decorators accept the same syntax:

  • Single exception: @throws(MyException)
  • Multiple exceptions: @throws([E1, E2, E3])
Original prompt

deprecate the use of @raises in reanalyze and use @throws instead.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Update reanalyze Exception.ml to accept both @throws and @raises decorators
- Update warning messages to use @throws terminology
- Add @throws decorator to completion with documentation
- Mark @raises as deprecated in completion
- Update all test files to use @throws instead of @raises
- Update expected test outputs to reflect @throws terminology
- Update Stdlib_JSON to use @throws instead of @raises

Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com>
Copilot AI changed the title [WIP] deprecate the use of @raises in reanalyze and use @throws instead. Deprecate @raises in favor of @throws in reanalyze Oct 2, 2025
Copilot AI requested a review from tsnobip October 2, 2025 09:45
@pkg-pr-new

pkg-pr-new Bot commented Oct 2, 2025 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7932

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7932

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7932

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7932

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7932

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7932

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7932

commit: 501eaa2

@tsnobip
tsnobip marked this pull request as ready for review October 2, 2025 10:49
@tsnobip

tsnobip commented Oct 2, 2025

Copy link
Copy Markdown
Member

fixes #7680.

@tsnobip
tsnobip requested a review from cknitt October 2, 2025 10:59

@cknitt cknitt 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.

We should check the terminology - are there still any other places using "raise" instead of "throw"

Comment thread analysis/reanalyze/src/Exception.ml Resolved
Comment thread analysis/reanalyze/src/Exception.ml Resolved
@cknitt

cknitt commented Oct 3, 2025

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

@cknitt
cknitt requested a review from cristianoc October 3, 2025 07:08
@tsnobip
tsnobip force-pushed the copilot/fix-ffd931b9-0aba-4a57-b568-72a4365d3180 branch from 2dc9cc9 to 4f5313a Compare October 3, 2025 07:16
@tsnobip
tsnobip requested a review from cknitt October 3, 2025 07:52
@tsnobip
tsnobip force-pushed the copilot/fix-ffd931b9-0aba-4a57-b568-72a4365d3180 branch from 01d9c83 to 501eaa2 Compare October 3, 2025 07:57
tsnobip added a commit to rescript-lang/rescript-lang.org that referenced this pull request Oct 3, 2025

@cknitt cknitt 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.

LGTM.
Maybe @cristianoc would like to have a look, too?

@tsnobip
tsnobip merged commit 11cde90 into master Oct 3, 2025
25 checks passed
@tsnobip
tsnobip deleted the copilot/fix-ffd931b9-0aba-4a57-b568-72a4365d3180 branch October 3, 2025 13:25
fhammerschmidt pushed a commit to rescript-lang/rescript-lang.org that referenced this pull request Oct 3, 2025
* Document the deprecation of @raises over @throws

Following the changes introduced by rescript-lang/rescript#7932

* document exception analysis in editor-plugins

* format

* update libraries set up to use exception analysis

* remove the outdated functor example for exception analysis

* rename List.hd to List.head (its name in Stdlib)

* rename functors to module functions
aspeddro pushed a commit to aspeddro/rescript-compiler that referenced this pull request Oct 31, 2026
* Initial plan

* Deprecate @raises in favor of @throws in reanalyze

- Update reanalyze Exception.ml to accept both @throws and @raises decorators
- Update warning messages to use @throws terminology
- Add @throws decorator to completion with documentation
- Mark @raises as deprecated in completion
- Update all test files to use @throws instead of @raises
- Update expected test outputs to reflect @throws terminology
- Update Stdlib_JSON to use @throws instead of @raises

Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com>

* replace other references of `raise` with `throw`

* update "Contribute to the API Reference"

* update changelog

* update docs some more

* rename some more raises

* rename raise to throw in API docs

* remove unused @throws annotations

* update completion

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com>
Co-authored-by: tsnobip <dontshootthink@gmail.com>
Signed-off-by: Pedro Castro <aspeddro@gmail.com>
cknitt added a commit that referenced this pull request Nov 3, 2026
Why:
    12.0.0-beta.14 deprecated `@raises` and `@doesNotRaise` in favour of
    `@throws` and `@doesNotThrow` (#7932). v13 drops the old spellings,
    the undeprecated `@throw` synonym, and the `@doNotThrow`/case variants,
    so one spelling remains for each annotation.

An old spelling is now an unknown attribute, so the code it annotated is
reported like unannotated code. The compiler's own `[@doesNotRaise]` and
`[@@raises]` annotations become `[@doesNotThrow]` and `[@@throws]`.

Reanalyze modified (old annotation spellings):
Example:
    @raises(Not_found)
    let oldRaisesAnnotation = () => throw(Not_found)
Before (reanalyze): no issue
After (reanalyze):
    Exception Analysis
    ExnOldSpellings.res:5:5-23
    oldRaisesAnnotation might throw Not_found (ExnOldSpellings.res:5:32) and is not annotated with @throws(Not_found)

Review: Why no dedicated warning for an old spelling? The missing-annotation report already names the `@throws(...)` to write, and recognizing the old names only to reject them would keep them in the analysis.
Breaking: `@raises`, `@raise`, `@throw`, `@doesNotRaise`, `@doNotRaise`, `@doNotThrow` and the lower-case variants are ignored; write `@throws` and `@doesNotThrow`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGhHjzBTXqSo8Dckpb
Signed-off-by: Christoph Knittel <ck@cca.io>
cknitt added a commit that referenced this pull request Nov 4, 2026
Why:
    12.0.0-beta.14 deprecated `@raises` and `@doesNotRaise` in favour of
    `@throws` and `@doesNotThrow` (#7932). v13 drops the old spellings,
    the undeprecated `@throw` synonym, and the `@doNotThrow`/case variants,
    so one spelling remains for each annotation.

An old spelling is now an unknown attribute, so the code it annotated is
reported like unannotated code. The compiler's own `[@doesNotRaise]` and
`[@@raises]` annotations become `[@doesNotThrow]` and `[@@throws]`.

Reanalyze modified (old annotation spellings):
Example:
    @raises(Not_found)
    let oldRaisesAnnotation = () => throw(Not_found)
Before (reanalyze): no issue
After (reanalyze):
    Exception Analysis
    ExnOldSpellings.res:5:5-23
    oldRaisesAnnotation might throw Not_found (ExnOldSpellings.res:5:32) and is not annotated with @throws(Not_found)

Review: Why no dedicated warning for an old spelling? The missing-annotation report already names the `@throws(...)` to write, and recognizing the old names only to reject them would keep them in the analysis.
Breaking: `@raises`, `@raise`, `@throw`, `@doesNotRaise`, `@doNotRaise`, `@doNotThrow` and the lower-case variants are ignored; write `@throws` and `@doesNotThrow`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGhHjzBTXqSo8Dckpb
Signed-off-by: Christoph Knittel <ck@cca.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants