public class DefaultErrorManager extends Object implements ErrorManager
ErrorManager
.Constructor and Description |
---|
DefaultErrorManager()
Creates a new
DefaultErrorManager instance with no given name. |
DefaultErrorManager(String sourceName)
Creates a new
DefaultErrorManager instance with the given name. |
Modifier and Type | Method and Description |
---|---|
boolean |
autoSummarize()
Should return true if
ErrorManager.summarize() should automatically be called at the end of parsing if there are errors and
the result wrapped and thrown by a new ProblemSummaryException . |
String |
getSourceName()
Gets the name of the source currently being parsed.
|
boolean |
hasErrors()
Returns true if there were any errors.
|
void |
report(ErrorLevel level,
Syntax cause,
String message)
Reports an error message.
|
void |
report(ParserException exception)
Reports an error based on a
ParserException . |
void |
report(SubscriptionException exception)
Reports an uncaught exception from a subscription method.
|
DefaultErrorManager |
rethrow(boolean rethrow)
Specifies whether reported exceptions should be rethrown as encountered, instead of reported as another error
message (default true).
|
String |
summarize()
Returns a summary of errors.
|
DefaultErrorManager |
warnings(boolean showWarnings)
Specifies whether to include warning messages in the summary (default true).
|
public DefaultErrorManager()
DefaultErrorManager
instance with no given name.public DefaultErrorManager(String sourceName)
DefaultErrorManager
instance with the given name.
The name is used to provide more meaningful information on what CSS file or resource caused the problem.
sourceName
- Name of the CSS file, to be used for error reporting.public DefaultErrorManager rethrow(boolean rethrow)
rethrow
- Specify true to rethrow reported Exceptions.public DefaultErrorManager warnings(boolean showWarnings)
showWarnings
- Specify true to include warning messages.public String getSourceName()
ErrorManager
getSourceName
in interface ErrorManager
public void report(ErrorLevel level, Syntax cause, String message)
ErrorManager
Validate
subscription methods.
Implementations should not throw or rethrow an exception from this method.
You can use ErrorUtils.format(Syntax, String)
as a helper.
report
in interface ErrorManager
level
- The ErrorLevel
.cause
- The Syntax
unit that is the cause of the error (e.g., the unit that has failed validation).message
- The error message.public void report(ParserException exception)
ErrorManager
ParserException
.
These are usually thrown by core parsers or custom refiner plugins, which is usually caused by bad CSS source code input.
report
in interface ErrorManager
exception
- The exception that describes the error.public void report(SubscriptionException exception)
ErrorManager
This will occur when a subscription plugin method throws an exception. This usually means there is a programming error in
the plugin, e.g., an NPE. It also might mean the plugin throws an unrelated (to the parser) exception which will results in
an InvocationTargetException
(this should be avoided).
Check the cause to find the underlying InvocationTargetException
.
report
in interface ErrorManager
exception
- The exception.public boolean hasErrors()
ErrorManager
hasErrors
in interface ErrorManager
public boolean autoSummarize()
ErrorManager
ErrorManager.summarize()
should automatically be called at the end of parsing if there are errors and
the result wrapped and thrown by a new ProblemSummaryException
.autoSummarize
in interface ErrorManager
ErrorManager.summarize()
should be called automatically.public String summarize()
ErrorManager
If there are no errors then this should return an empty string.
summarize
in interface ErrorManager
Copyright (c) 2019, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE file in the repository.