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

File not found with @extend throws error, instead of calling the callback #119

Open
Ishmael-Turner opened this issue Nov 10, 2016 · 0 comments

Comments

@Ishmael-Turner
Copy link

Ishmael-Turner commented Nov 10, 2016

I have an HTML file with:

<!-- @extend non-existant-file.html -->

I am using Promises to chain various build steps together and calling preprocessFile with a callback inside the Promise constructor. When the code is run an exception is raised for the missing file and I cannot catch it with try...catch or Promise.catch(). This causes the entire script to halt.

As this build task is ran inside a file watcher (BrowserSync/chokidar) it halts the server, rather than giving me a chance to edit and save with automatic re-build. Here's a simplified version of the code, omitting the BrowserSync bit.

function html() {
    return globby( 'app/*.html')
        .then( (htmlFiles) => {
            var ppHtmlPs = htmlFiles.map( (file) => {
                return new Promise( (resolve, reject) => {
                    var destFileName = path.join( 'temp', path.basename(file) );

                    pp.preprocessFile( file, destFileName, {}, (err) => {
                        if (err) {
                            reject(err);
                        } else {
                            resolve();
                        }
                    }, {
                        type: 'html',
                        srcEol: '\r\n',
                        fileNotFoundSilentFail: false
                    } );
                } );
            } );
            return Promise.all( ppHtmlPs );
        } )
        .catch( (reason) => {
            console.error(reason.message);
        } );
}

I could resort to fileNotFoundSilentFail: true and add a Promise.then() handler to check for the error message written into the output. It's not a big issue but a callback for this error would make for more natural code.

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