Skip to content

How should bindings handle function argument type errors #11

@Place1

Description

@Place1

When JS calls native functions but passes incorrect arguments how strict should the bindings be?

example:

const window = new Gtk.Window();
window.setTitle("hello"); // valid
window.setTitle(["hello"]); // invalid

Should the invalid arguments call result in:

  1. Do what GJS does and log a warning to stderr and then do nothing (pretend the function was never called).
  2. Throw a JS error with a message detailing what was expected and what was given.

I'm a fan of the strictness being enforced by option 2 but GJS is lenient in this regard by just logging an error and then not doing the native call.

Personally I think option 1 can lead to harder to solve bugs. While GJS does log a very small stack trace this is not the same as a real uncaught error from the engine itself. It will not trigger tooling around uncaught errors that a nodejs program might have such as process.on('uncaughtException', ...);, and if the program has noisy output if can become very difficult to see the tree from the forest. Clearly i'm biased towards option 2 but this is easy to change so i've created this issue incase someone has some good reasons I may have missed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions