Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 2, 2025

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 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 Copilot AI requested a review from tsnobip October 2, 2025 09:45
Copilot finished work on behalf of tsnobip October 2, 2025 09:45
Copy link

pkg-pr-new bot commented Oct 2, 2025

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
Copy link
Member

tsnobip commented Oct 2, 2025

fixes #7680.

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

@cknitt cknitt left a comment

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"

@cknitt
Copy link
Member

cknitt commented Oct 3, 2025

@codex review

Copy link

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
Copy link
Member

@cknitt cknitt left a comment

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
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