Nativescript: Rework error handling for synchronous file system module API

Created on 12 Sep 2018  路  3Comments  路  Source: NativeScript/NativeScript

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.

feature

Most helpful comment

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

All 3 comments

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)

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

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...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fmmsilva picture fmmsilva  路  3Comments

vtisnado picture vtisnado  路  3Comments

minjunlan picture minjunlan  路  3Comments

rLoka picture rLoka  路  3Comments

guillaume-roy picture guillaume-roy  路  3Comments