Skip to content

Commit fd46de2

Browse files
cknittclaude
andcommitted
Accept only @throws and @doesNotThrow in reanalyze
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>
1 parent 6741bab commit fd46de2

34 files changed

Lines changed: 137 additions & 120 deletions

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ Some tips:
490490
- The first sentence or line should show the function call with a very short summary.
491491
- Ideally, every function should have an `## Examples` section with **at least one** example. The examples are compiled to check that they are correct. Use `==` to generate tests from the examples.
492492
- Always use `@deprecated` when applicable.
493-
- Always use `@throw` when applicable.
493+
- Always use `@throws` when applicable.
494494
- Always provide a `See` section pointing to MDN for more information when available.
495495

496496
## Contribute to JSX `domProps`

‎analysis/reanalyze/src/arnold.ml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,10 @@ module Compile = struct
833833
| _ ->
834834
Stats.log_hygiene_named_arg_value ~label ~loc;
835835
raise ArgError
836-
[@@raises ArgError]
836+
[@@throws ArgError]
837837
in
838838
function_arg ()
839-
[@@raises ArgError]
839+
[@@throws ArgError]
840840
in
841841
let function_args_opt =
842842
try Some (function_definition.kind |> List.map get_function_arg)

‎analysis/reanalyze/src/exception.ml‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,7 @@ let traverse_ast ~file ~values_builder ~checks_builder () =
313313
in
314314
let does_not_throw attributes =
315315
attributes
316-
|> Annotation.get_attribute_payload (function
317-
| "doesNotRaise" | "doesnotraise" | "DoesNoRaise" | "doesNotraise"
318-
| "doNotRaise" | "donotraise" | "DoNoRaise" | "doNotraise"
319-
| "doesNotThrow" | "doesnotthrow" | "DoesNoThrow" | "doesNotthrow"
320-
| "doNotThrow" | "donotthrow" | "DoNoThrow" | "doNotthrow" ->
321-
true
322-
| _ -> false)
316+
|> Annotation.get_attribute_payload (fun s -> s = "doesNotThrow")
323317
<> None
324318
in
325319
let expr ~(module_path : Module_path.t) (self : Tast_mapper.mapper)
@@ -425,9 +419,7 @@ let traverse_ast ~file ~values_builder ~checks_builder () =
425419
in
426420
let get_exceptions_from_annotations attributes =
427421
let throws_annotation_payload =
428-
attributes
429-
|> Annotation.get_attribute_payload (fun s ->
430-
s = "throws" || s = "throw" || s = "raises" || s = "raise")
422+
attributes |> Annotation.get_attribute_payload (fun s -> s = "throws")
431423
in
432424
let rec get_exceptions payload =
433425
match payload with

‎analysis/reanalyze/src/log_.ml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ let item x =
9595
Format.fprintf Format.std_formatter " ";
9696
Format.fprintf Format.std_formatter x
9797

98-
let missing_raise_info_to_text {Issue.missing_annotations; loc_full} =
98+
let missing_throw_info_to_text {Issue.missing_annotations; loc_full} =
9999
let missing_txt =
100100
Format.asprintf "%a" (Exceptions.pp ~exn_table:None) missing_annotations
101101
in
@@ -107,8 +107,8 @@ let missing_raise_info_to_text {Issue.missing_annotations; loc_full} =
107107

108108
let log_additional_info ~(description : Issue.description) =
109109
match description with
110-
| ExceptionAnalysisMissing missing_raise_info ->
111-
missing_raise_info_to_text missing_raise_info
110+
| ExceptionAnalysisMissing missing_throw_info ->
111+
missing_throw_info_to_text missing_throw_info
112112
| _ -> ""
113113

114114
let missing_throw_info_to_message
@@ -131,8 +131,8 @@ let description_to_message (description : Issue.description) =
131131
| DeadWarning {path; message} ->
132132
Format.asprintf "@{<info>%s@} %s" path message
133133
| ExceptionAnalysis {message} -> message
134-
| ExceptionAnalysisMissing missing_raise_info ->
135-
missing_throw_info_to_message missing_raise_info
134+
| ExceptionAnalysisMissing missing_throw_info ->
135+
missing_throw_info_to_message missing_throw_info
136136
| Termination {message} -> message
137137

138138
let description_to_name (description : Issue.description) =

‎analysis/reanalyze/src/reanalyze.ml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ let parse_argv (argv : string array) : string option =
338338
let version_and_exit () =
339339
print_endline usage;
340340
exit 0
341-
[@@raises exit]
341+
[@@throws exit]
342342
in
343343
let rec set_all cmt_root =
344344
Run_config.all ();
@@ -475,7 +475,7 @@ let parse_argv (argv : string array) : string option =
475475
let cli () =
476476
let cmt_root = parse_argv Sys.argv in
477477
run_analysis_and_report ~cmt_root
478-
[@@raises exit]
478+
[@@throws exit]
479479

480480
(* Re-export server module for external callers (e.g. tools/bin/main.ml).
481481
This keeps the wrapped-library layering intact: Reanalyze depends on internal

‎analysis/src/completion_decorators.ml‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@ Alternatively, use the `@@deprecated` decorator to add a deprecation warning to
3838

3939
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#expression-deprecated-decorator).|};
4040
] );
41-
( "doesNotRaise",
42-
None,
43-
[
44-
{|The `@doesNotRaise` decorator is deprecated. Please use `@doesNotThrow` instead.
45-
46-
`@doesNotRaise` is uses to override the analysis and state that an expression does not throw any exceptions,
47-
even though the analysis reports otherwise. This can happen for example in the case of array access where
48-
the analysis does not perform range checks but takes a conservative stance that any access
49-
could potentially throw.
50-
[Read more and see examples in the documentation](https://github.com/rescript-association/reanalyze/blob/master/EXCEPTION.md).
51-
> Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|};
52-
] );
5341
( "doesNotThrow",
5442
None,
5543
[
@@ -151,17 +139,6 @@ The `@new` decorator is used whenever you need to bind to a JavaScript class con
151139

152140
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#obj-decorator).|};
153141
] );
154-
( "raises",
155-
Some "raises(\"$0\")",
156-
[
157-
{|The `@raises` decorator is deprecated. Please use `@throws` instead.
158-
159-
`@raises` acknowledges that a function can throw exceptions that are not caught, and suppresses
160-
a warning in that case. Callers of the functions are then subjected to the same rule.
161-
Example `@raises(Exn)` or `@raises([E1, E2, E3])` for multiple exceptions.
162-
[Read more and see examples in the documentation](https://github.com/rescript-association/reanalyze/blob/master/EXCEPTION.md).
163-
> Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|};
164-
] );
165142
( "throws",
166143
Some "throws(\"$0\")",
167144
[

‎analysis/src/process_cmt.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ let rec for_structure_item ~(env : Shared_types.Env.t) ~(exported : Exported.t)
550550
{mb_id; mb_attributes; mb_loc; mb_name = name; mb_expr = {mod_desc}}
551551
when not
552552
(String.length name.txt >= 6
553-
&& (String.sub name.txt 0 6 = "local_") [@doesNotRaise])
553+
&& (String.sub name.txt 0 6 = "local_") [@doesNotThrow])
554554
(* %%private generates a dummy module called local_... *) ->
555555
let item = for_module ~env mod_desc name.txt in
556556
let declared =
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Reanalyze no longer honors `@raises`, `@raise`, `@throw`, `@doesNotRaise` or the other `@doesNotThrow` variants: write `@throws` and `@doesNotThrow` instead.

‎compiler/ext/ext_util.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let string_of_int_as_char (i : int) : string =
3434
| '\r' -> "\\r"
3535
| '\b' -> "\\b"
3636
| ' ' .. '~' as c ->
37-
let s = (Bytes.create [@doesNotRaise]) 1 in
37+
let s = (Bytes.create [@doesNotThrow]) 1 in
3838
Bytes.unsafe_set s 0 c;
3939
Bytes.unsafe_to_string s
4040
| _ when Uchar.is_valid i -> Ext_utf8.encode_codepoint i

‎compiler/gentype/emit_js.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ let rec read_cmt_files_recursively ~config ~env
457457
|> create_export_type_map ~config ~from_cmt_read_recursively:true
458458
~file:
459459
(cmt_file |> Filename.basename
460-
|> (Filename.chop_extension [@doesNotRaise]))
460+
|> (Filename.chop_extension [@doesNotThrow]))
461461
in
462462
let cmt_to_export_type_map =
463463
env.cmt_to_export_type_map

0 commit comments

Comments
 (0)