mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
This is valuable information for Node applications that need to figure out why a particular system call failed. Note that errno can either be a string or a number, which is why I have typed it as 'any'. While this is undocumented, it is tested: Code property: https://github.com/joyent/node/blob/v0.10.23-release/test/simple/test-fs-open.js#L34 Errno property [string]: https://github.com/joyent/node/blob/v0.10.23-release/test/internet/test-dns.js#L148 Errno property [number]: https://github.com/joyent/node/blob/v0.10.23-release/test/simple/test-domain-implicit-fs.js#L43 Syscall property: https://github.com/joyent/node/blob/v0.10.23-release/test/simple/test-stdout-close-catch.js#L38 Path property (I can’t find a test, but many examples have this line): https://github.com/joyent/node/blob/v0.10.23-release/deps/npm/node_modules/fstream-npm/example/bundle.js#L6 ..and well supported in the code for all platforms (this is where I got the name 'ErrnoException' from): *nix: https://github.com/joyent/node/blob/v0.10.23-release/src/node.cc#L719 Windows: https://github.com/joyent/node/blob/v0.10.23-release/src/node.cc#L856 Unfortunately, while every errno exception is guaranteed to have the ‘errno’ and ‘code’ properties (see the logic in the source code in node.cc), there is no hard guarantee that particular library functions will always pass an ErrnoException to the callback. I cannot find a counterexample at this moment, though. Since we can’t have union types in TypeScript, I simply made all of the properties on ErrnoException optional as a compromise. I am only adding modifications to the fs module, which definitely throws ErrnoExceptions. But according to the examples above, other modules (e.g. dns) also pass errno information back to applications. People familiar with those other modules can update their typings to reference this interface when applicable; I lack the experience with those modules to update their typings. Further proof: ```javascript $ node > var fs = require('fs'); undefined > fs.open('doesntexistlol', 'r', function(e) { console.log(Object.keys(e)); console.log(e.code); console.log(e.errno); console.log(e.path); }); undefined > [ 'errno', 'code', 'path' ] ENOENT 34 doesntexistlol ``` |
||
|---|---|---|
| .. | ||
| node-0.8.8.d.ts | ||
| node-0.8.8.d.ts.tscparams | ||
| node-tests.ts | ||
| node.d.ts | ||