Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Error modules cleanup #7408

wants to merge 2 commits into from

Conversation

tsnobip
Copy link
Member

@tsnobip tsnobip commented Apr 26, 2025

Fixes #7377:

  • renamed exception from JsError to JsExn
  • created a Stdlib.JsExn module around a type t = unknown and utility functions like @get external name: t => option<string> = "name" returning options
  • created a Stdlib.JsError module to limit the confusion with Result.Error. Unlike Stdlib.Error.t, in this module, type t is be abstract.
  • deprecated the types and functions from the old modules Stdlib.Error and Stdlib.Exn

@tsnobip tsnobip force-pushed the clean-error-exn-modules branch from d526cc1 to f36764d Compare April 26, 2025 14:51
@tsnobip tsnobip force-pushed the clean-error-exn-modules branch from f36764d to 1f7f255 Compare April 26, 2025 14:54
@tsnobip tsnobip requested review from cknitt, cometkim and Copilot April 26, 2025 14:57
Copy link

@Copilot Copilot AI left a 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;

```
*/
@get
external name: t => option<string> = "name"
Copy link
Member

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.

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.

Copy link
Member Author

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!

@tsnobip tsnobip requested review from cknitt and CarlOlson April 28, 2025 07:43
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 now.
But maybe @cometkim wants to have a look, too.

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.

Error modules cleanup
3 participants