-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
Handle failure for readFileSync #22
Comments
Just a thought, but maybe brfs could inline something like |
What is your particular use case for this feature? |
I'm reading in a manifest generated by gulp-rev and writing it into browserified output so that lookups of unrevved-to-revved assets can be shared in node and the browser. In development, I'm not writing this file, and so the fs.readFileSync call in my module fails and I can't do anything to stop it (the same is true of |
Any update on this issue? |
This is interesting but I'm not 100% sure about it. I like that brfs currently emits a build error; it allows broken files to show in the browser with I will brew on it. 😄 |
Sorry for sending that IIFE suggestion too early. Example code for the custom config use case: 'use strict';
var fs = require('fs'), config,
defaultConfig = require('../package.json').defaultConfig;
try {
config = fs.readFileSync(__dirname + '/customConfig.json', 'utf8');
config = JSON.parse(config);
} catch (readOrJsonErr) {
config = null;
}
if (!config) { config = defaultConfig; }
console.log('sync:', config);
fs.readFile(__dirname + '/customConfig.json', 'utf8', function (readErr, cfg) {
cfg = ((!readErr) && JSON.parse(cfg)) || defaultConfig;
console.log('async:', cfg);
});
Maybe brfs can inline throwing IIFEs in cases where it's easy to detect that the read operation is called inside a try {} block? For instances where the code authors intend to use brfs, we could add brfs APIs that convey more info about how to translate them, like |
In node I can wrap a call to readFileSync in a synchronous try/catch:
and running it will write
caught!
but running throughbrowserify -t brfs
givesIs there a way that the same thing with brfs? I know that brfs processes the source statically, but I'm doing things like running the source through
envify
first and the fs call could fail and stop the build. Probably does so for the best, but I was wondering if there is a way to inline an empty string, undefined, etc.Thanks substack!
The text was updated successfully, but these errors were encountered: