Constructor
new CssSyntaxError(message, lineopt, columnopt, sourceopt, fileopt, pluginopt)
- Source:
Examples
// Catching and checking syntax error
try {
postcss.parse('a{')
} catch (error) {
if ( error.name === 'CssSyntaxError' ) {
error //=> CssSyntaxError
}
}
// Raising error from plugin
throw node.error('Unknown variable', { plugin: 'postcss-vars' });
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
message |
string | error message |
|
line |
number |
<optional> |
source line of the error |
column |
number |
<optional> |
source column of the error |
source |
string |
<optional> |
source code of the broken file |
file |
string |
<optional> |
absolute path to the broken file |
plugin |
string |
<optional> |
PostCSS plugin name, if error came from plugin |
Members
column :number
- Source:
Source column of the error.
Type:
- number
Example
error.column //=> 1
error.input.column //=> 4
file :string
- Source:
Absolute path to the broken file.
Type:
- string
Example
error.file //=> 'a.sass'
error.input.file //=> 'a.css'
input :Input
- Source:
Input object with PostCSS internal information about input file. If input has source map from previous tool, PostCSS will use origin (for example, Sass) source. You can use this object to get PostCSS input source.
Type:
Example
error.input.file //=> 'a.css'
error.file //=> 'a.sass'
line :number
- Source:
Source line of the error.
Type:
- number
Example
error.line //=> 2
error.input.line //=> 4
message :string
- Source:
Full error text in the GNU error format with plugin, file, line and column.
Type:
- string
Example
error.message //=> 'a.css:1:1: Unclosed block'
name :string
- Source:
Always equal to 'CssSyntaxError'. You should
always check error type
by error.name === 'CssSyntaxError' instead of
error instanceof CssSyntaxError, because
npm could have several PostCSS versions.
Type:
- string
Example
if ( error.name === 'CssSyntaxError' ) {
error //=> CssSyntaxError
}
plugin :string
- Source:
Plugin name, if error came from plugin.
Type:
- string
Example
error.plugin //=> 'postcss-vars'
reason :string
- Source:
Error message.
Type:
- string
Example
error.message //=> 'Unclosed block'
source :string
- Source:
Source code of the broken file.
Type:
- string
Example
error.source //=> 'a { b {} }'
error.input.column //=> 'a b { }'
Methods
showSourceCode(coloropt) → {string}
- Source:
Returns a few lines of CSS source that caused the error.
If the CSS has an input source map without sourceContent,
this method will return an empty string.
Example
error.showSourceCode() //=> " 4 | }
// 5 | a {
// > 6 | bad
// | ^
// 7 | }
// 8 | b {"
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
color |
boolean |
<optional> |
whether arrow will be colored red by terminal
color codes. By default, PostCSS will detect
color support by |
Returns:
few lines of CSS source that caused the error
- Type
- string
toString() → {string}
- Source:
Returns error position, message and source code of the broken part.
Example
error.toString() //=> "CssSyntaxError: app.css:1:1: Unclosed block
// > 1 | a {
// | ^"
Returns:
error position, message and source code
- Type
- string