Skip to content

Instantly share code, notes, and snippets.

@reporter123
Last active December 3, 2022 01:53
Show Gist options
  • Save reporter123/7c10e565fb849635787321766b7f8ad8 to your computer and use it in GitHub Desktop.
Save reporter123/7c10e565fb849635787321766b7f8ad8 to your computer and use it in GitHub Desktop.
Compelete typescript definition for node's SystemError. A partial definition exists within TypeScript.
/*
Missing from TypeScript but documented by node.
See https://nodejs.org/api/errors.html#class-systemerror
*/
interface NodeSystemError extends Error{
address?: string; //If present, the address to which a network connection failed
code:string;// The string error code
dest:string;// If present, the file path destination when reporting a file system error
errno:number;// The system-provided error number
info?:Object;// If present, extra details about the error condition
message:string;// A system-provided human-readable description of the error
path?:string;// If present, the file path when reporting a file system error
port?:number;// If present, the network connection port that is not available
syscall:string;// The name of the system call that triggered the error
}
export type { NodeSystemError };
@dami-i
Copy link

dami-i commented Jul 18, 2022

Extremely useful. Thank you!

@reporter123
Copy link
Author

I believe I eventual found some of this in the existing typescript files but nothing like this where it was all in one place.

@runk
Copy link

runk commented Nov 28, 2022

You may want to use NodeJS.ErrnoException from @types/node, which is somewhat similar

@reporter123
Copy link
Author

I wrote this before discovering the official type which is preferable since it will be kept updated should node change. The official type does not currently include all documented attributes. However it should work for most use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment