-
Notifications
You must be signed in to change notification settings - Fork 464
Error modules cleanup #7408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Error modules cleanup #7408
Conversation
d526cc1
to
f36764d
Compare
f36764d
to
1f7f255
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR cleans up error modules by renaming the exception from JsError to JsExn, introducing a dedicated Stdlib.JsExn module, and deprecating the old error-related modules. Key changes include:
- Renaming exception identifiers across multiple files.
- Creating new modules (Stdlib.JsExn and Stdlib.JsError) to provide clearer JavaScript error abstractions.
- Updating documentation and the changelog to reflect these changes.
Reviewed Changes
Copilot reviewed 61 out of 68 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
packages/artifacts.txt | Added new entries for Stdlib_JsError and Stdlib_JsExn. |
lib/js/Stdlib_JsExn.js | Introduced helper module for handling JsExn conversion. |
lib/js/Stdlib_JsError.js | Provided utility functions for throwing various errors. |
lib/js/Stdlib_Exn.js | Updated error literal from "JsError" to "JsExn". |
lib/js/Stdlib.js | Redirected panic function to Stdlib_JsError and exported JsError/JsExn (but variables remain unassigned). |
lib/js/Primitive_exceptions.js | Updated error literal from "JsError" to "JsExn". |
lib/es6/Stdlib_JsExn.js | Added ES6 version of the JsExn module. |
lib/es6/Stdlib_JsError.js | Added ES6 version of the JsError module. |
lib/es6/Stdlib_Exn.js | Updated error literal from "JsError" to "JsExn". |
lib/es6/Stdlib.js | Redirected panic function to Stdlib_JsError and exported JsError/JsExn (but variables remain unassigned). |
lib/es6/Primitive_exceptions.js | Updated error literal from "JsError" to "JsExn". |
compiler/core/design.md | Updated terminology in documentation to "JS exception". |
CHANGELOG.md | Documented the breaking change and module renaming. |
Files not reviewed (7)
- analysis/examples/workspace-project/myplugin/src/Promise.res: Language not supported
- analysis/reanalyze/src/Exn.ml: Language not supported
- analysis/reanalyze/src/Exn.mli: Language not supported
- analysis/reanalyze/src/ExnLib.ml: Language not supported
- compiler/frontend/ast_exp_extension.ml: Language not supported
- compiler/ml/predef.ml: Language not supported
- runtime/Primitive_exceptions.res: Language not supported
Comments suppressed due to low confidence (4)
lib/js/Stdlib.js:50
- The variable 'JsError' is declared but not assigned a value. Consider importing and assigning the appropriate module (e.g., from Stdlib_JsError) to ensure it can be used correctly.
let JsError;
lib/js/Stdlib.js:52
- The variable 'JsExn' is declared but not assigned any value. Assign it from the corresponding module if it is intended for production usage.
let JsExn;
lib/es6/Stdlib.js:50
- In the ES6 Stdlib file, the 'JsError' variable is declared without assignment. Import and assign the module to ensure it is correctly initialized for use.
let JsError;
lib/es6/Stdlib.js:52
- The variable 'JsExn' in the ES6 Stdlib file is declared but never initialized. Consider importing and assigning the proper module to avoid potential runtime issues.
let JsExn;
runtime/Stdlib_JsExn.resi
Outdated
``` | ||
*/ | ||
@get | ||
external name: t => option<string> = "name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function and the others in this module are unsafe.
t
is unknown
and so could be anything, including for example an object that has a name
property that is of type number
or object
instead of string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could also be null
, just this week I added code like this to a project:
let name: t => option<string> = %raw(`t => typeof t?.name === "string" ? t.name : undefined`)
As an aside, it would be awesome if the compiler had support for something like @get(null_coalesce)
that worked with @scope
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cknitt @CarlOlson I fixed it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now.
But maybe @cometkim wants to have a look, too.
Fixes #7377:
JsError
toJsExn
Stdlib.JsExn
module around atype t = unknown
and utility functions like@get external name: t => option<string> = "name"
returning optionsStdlib.JsError
module to limit the confusion withResult.Error
. UnlikeStdlib.Error.t
, in this module,type t
is be abstract.Stdlib.Error
andStdlib.Exn