Skip to content

Commit

Permalink
update createErrorMessage function
Browse files Browse the repository at this point in the history
  • Loading branch information
jellizaveta committed Dec 2, 2024
1 parent 6a3b67e commit 5405295
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/filters-downloader-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,25 +236,30 @@ const FiltersDownloaderCreator = (FileDownloadWrapper: IFileDownloader): IFilter
* Creates a detailed error message with context information.
*
* @param message The main error message.
* @param directive The directive line that caused the error.
* @param contextLines The lines of context before the error.
* @param line The line where the error occurred.
* @param contextStr The context string (3 lines before) to include in the error message.
* @param url The URL of the filter file.
* @returns The formatted error message string.
*/
const createErrorMessage = (
message: string,
directive: string,
contextLines?: string,
line: string,
contextStr?: string,
url?: string,
): string => {
const errorText = `
${message} '${directive}'
${url ? `URL: '${url}'` : ''}
Context:
${contextLines}
\t${directive}`;

return `${dedent(errorText)}\n`;
const errorChunks = [`${message} '${line}'`];

if (url) {
errorChunks.push(`URL: '${url}'`);
}

if (contextStr) {
errorChunks.push('Context:');
errorChunks.push(contextStr);
errorChunks.push(`\t${line}`);
}

return `${dedent(errorChunks.join('\n'))}\n`;
};

/**
Expand Down Expand Up @@ -539,7 +544,7 @@ const FiltersDownloaderCreator = (FileDownloadWrapper: IFileDownloader): IFilter
// check if there is something after !#else
if (rules[elseLineIndex].trim().length !== CONDITION_ELSE_DIRECTIVE_START.length) {
errorMessage = createErrorMessage(
'Invalid directives: Found invalid !#else:',
'Found invalid directive !#else',
rule,
context,
urlOrigin,
Expand Down

0 comments on commit 5405295

Please sign in to comment.