NativeScript icon indicating copy to clipboard operation
NativeScript copied to clipboard

Rework error handling for synchronous file system module API

Open manoldonev opened this issue 7 years ago • 3 comments

Currently the error handling for the synchronous file system module API is performed via optional error callbacks that are passed as last parameter to the respective "sync" method. This approach is rather unconventional and unintuitive:

file.writeTextSync("some text", (err) => console.log(err));

Rework the error handling logic for the "sync" methods to be similar to the nodejs approach with try...catch blocks:

try {
    file.writeTextSync("some text");
} catch (err) {
    console.log(err);
}

Related to https://github.com/NativeScript/docs/issues/1111


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

manoldonev avatar Sep 12 '18 11:09 manoldonev

Totally agree the API with try/catch is much better.

Maybe we can implement a back-compatible approach. For example, if an error occurs

  • If there is errorCallback - just call it and leave the user to handle it (the old way)
  • If there is not -> throw the error (the new way)

vakrilov avatar Sep 12 '18 11:09 vakrilov

Yup, we can do that but I would still remove the "old" way from our documentation / examples.

manoldonev avatar Sep 12 '18 12:09 manoldonev

Please support the old way; there are several plugins in the ecosystem that use the FS module for things; and I know I don't really want to make the plugins incompatible with people still using NS 4...

NathanaelA avatar Sep 12 '18 16:09 NathanaelA