Skip to content
This repository was archived by the owner on May 10, 2023. It is now read-only.
This repository was archived by the owner on May 10, 2023. It is now read-only.

'Root font-size is invalid' Error does not contain .source #46

Closed
@TrevorPT

Description

@TrevorPT

Hello,

I'm using pixrem with bluebird promises to process a series of .css files. I want to use the root font-size from the .css file but I hit one file that does not have the font-size set on the html node and pixrem is throwing an error: Root font-size is invalid. Unlike a CssSyntaxError, the Error object does not include the source so I cannot tell which source caused the error. When pixrem throws a CssSyntaxError, it includes a .source property so that I can just return the original source css up the bluebird chain via .catch.

.then( function ( cssBuffer ) {
    var css = PostCSSPixrem.process( cssBuffer, null, { atrules: true } );
    return css; // returns a string
} )
.catch( function ( error ) {
    // catch PostCSS parsing errors
    if ( error.name === 'CssSyntaxError' ) {
        // Just return the original source css
        return error.source;
    }
    // catch any file errors, like a missing file
    if ( error.fileName ) {
        return null;
    }
    // else an unexpected error
    // Try to return the original source css if available
    return error.source;
} )

Can pixrem include the source in the thrown Error or is there a better way for me to do this?

Thanks, and thanks for a useful library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions