jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.07k stars 217 forks source link

Better file system options checking and error messages #183

Closed jvilk closed 7 years ago

jvilk commented 7 years ago

All file system backends now accept an options object that contains configuration options for the backend. Some options are required, others are optional.

However... users may (and do!) provide incorrect options for a file system, resulting in unintelligible error messages. This problem is exacerbated with the new BrowserFS.configure() API, where the bug may be in any of the nested file systems specified in the configuration option.

To fix this issue, file systems should export a static property describing the shape of the options object expected. In particular, it should contain the following information for each option:

Using this information, BrowserFS can dynamically check the options furnished to the file system for errors, and print out intelligible error messages.

One implementation annoyance is that every Create function needs to be modified to include the check. Rather than force this on file system implementors, BrowserFS could automatically wrap every file system's Create function to check options / handle the case where options is not provided. This would simplify the existing Create functions for file systems with no options, like the InMemory file system.

jvilk commented 7 years ago

Also, we can use Levenshtein distance to suggest alternatives when a fs string or option name is misspelled.

jvilk commented 7 years ago

Note: This change should be covered by unit tests, and is easily testable by checking the error message.