Skip to content

Conversation

@abd0-omar
Copy link
Contributor

Description

Use Tag enum instead of strings in load::from_single_file, load::from_file and load::from_memory.
Prevents runtime errors from invalid tags like "rust" instead of "rs".

Fixes #585

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Documentation update

Checklist:

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests/screenshots (if any) that prove my fix is effective or that my feature works.
  • I have tested the tests implicated (if any) by my own code and they pass (make test or ctest -VV -R <test-name>).
  • If my change is significant or breaking, I have passed all tests with ./docker-compose.sh test &> output and attached the output.
  • I have tested my code with OPTION_BUILD_ADDRESS_SANITIZER or ./docker-compose.sh test-address-sanitizer &> output and OPTION_TEST_MEMORYCHECK.
  • I have tested my code with OPTION_BUILD_THREAD_SANITIZER or ./docker-compose.sh test-thread-sanitizer &> output.
  • I have tested with Helgrind in case my code works with threading.
  • I have run make clang-format in order to format my code and my code follows the style guidelines.

If you are unclear about any of the above checks, have a look at our documentation here.

Use Tag enum instead of strings in `load::from_single_file`,
`load::from_file` and `load::from_memory`.
Prevents runtime errors from invalid tags like 'rust' instead of 'rs'.
Copy link
Collaborator

@fahdfady fahdfady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Job @abd0-omar Thanks :)
I just have a few concerns to raise.

ptr,
};

pub enum Tag {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think names here in the enum has to be exactly matched with the loaders names provided here https://github.com/metacall/core/tree/develop/source/loaders.

Like Node not NodeJS
Ts not TypeScript
Rb not Ruby
and provide /// comments to show the LSP what this tag's language is, matching our Enum with the original MetaCall API.
That's my opinion, I need to know yours.
@viferga @hulxv


let scripts_dir = env::current_dir().unwrap().join("tests/scripts");
let inavlid_file = scripts_dir.join("whatever.yeet");
let valid_file = scripts_dir.join("script.js");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we change this? this is supposed to be a test that points to invalid loaders.

let js_file = scripts_dir.join("script.js");

if let Err(MetaCallLoaderError::FileNotFound(_)) =
load::from_single_file("random", inavlid_file)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too should be left to fail.
I guess the test at all will be outdated and removed because of the feature we implemented. The Enum will make us impossible to fail, compile-time.

@viferga
Copy link
Member

viferga commented Oct 29, 2025

I am going to merge it and I will change your suggestions later on @fahdfady

@viferga viferga merged commit ac2228f into metacall:develop Oct 29, 2025
49 of 56 checks passed
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.

rust port: use enum for tag in load module

3 participants