Open
Description
When fs.writeFileSync () is invoked with a non-legal path ( for example a path longer than the underlying platform path limit, which might be different in each operating system), it throws an error ENAMETOOLONG, name too long.
This exception crashes the current execution of the code.
it.only 'Path too long unhandled exception', ->
content = (20).random_Letters();
tempFile = './src' + (20000).random_Letters()
try
content.saveAs(tempFile)
catch error
#Identifying error code
error.code.assert_Is('ENAMETOOLONG')
error.toString().assert_Contains('Error: ENAMETOOLONG, name too long')
There are two ways to fix this :
- Adding a try-catch block when fs.writeFileSync () is invoked and log the error.
- Add a check for the path before invoking the function.
Option 2 seems to be tricky since we would need to know,somehow, what is the path limit of the underlying operating system, then we need to do an input validation for the path to see if it is not longer than the limit.
According to the documentation fs.writeFileSync () does not return nothing.
Metadata
Metadata
Assignees
Labels
No labels