Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handling exceptions fro fs.saveAs(). If file path is too large, it crashes the current execution #79

Open
michaelhidalgo opened this issue Apr 10, 2015 · 2 comments

Comments

@michaelhidalgo
Copy link
Contributor

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 :

  1. Adding a try-catch block when fs.writeFileSync () is invoked and log the error.
  2. 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.

@michaelhidalgo
Copy link
Contributor Author

Here is an example on why this is an important fix
TeamMentor/TM_4_0_Design#682

@michaelhidalgo
Copy link
Contributor Author

it.only 'Path too long unhandled exception', ->
    content  = (20).random_Letters();
    tempFile = './src' + (250).random_Letters()
    try
      content.saveAs(tempFile)
      tempFile.length.assert_Is(255)
    catch error
      error.code.assert_Is('ENAMdETOOLONG')
      error.toString().assert_Contains('Error: ENAMETOOLONG, name too long')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant