Skip to content

Commit

Permalink
fix error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jellizaveta committed Dec 4, 2024
1 parent 47fafe8 commit ddd9ac0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions __tests__/filters-downloader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Context:
\t||example.com
\t||example.org
\t!#include ${nonExistentFilePath}
\tENOENT: no such file or directory, open '${nonExistentFilePath}'
\tError: ENOENT: no such file or directory, open '${nonExistentFilePath}'
`),
);
});
Expand All @@ -101,7 +101,7 @@ Context:
\t||example.org^
\t||example.com^
\t!#include
\tEISDIR: illegal operation on a directory, read
\tError: EISDIR: illegal operation on a directory, read
`),
);
});
Expand Down
17 changes: 8 additions & 9 deletions _qunit_tests_/filters-downloader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,14 @@ QUnit.test('Test filter downloader - compile rules with conditional includes', a
'!#endif',
];

try {
await FiltersDownloader.compile(rules, null, FilterCompilerConditionsConstants);
} catch (e) {
assert.equal(
(e as Error).message,
// eslint-disable-next-line max-len
`Failed to resolve the include directive: '!#include ${URL404}'`,
);
}
assert.rejects(
FiltersDownloader.compile(rules, null, FilterCompilerConditionsConstants),
`Failed to resolve the include directive '!#include https://raw.githubusercontent.com/AdguardTeam/FiltersDownloader/test-resources/__test__/resources/blabla.txt'
Context:
always_included_rule
!#include ${URL404}
Response status for url ${URL404} is invalid: 404`,
);

// case 3: negative condition and include non-existing url
rules = [
Expand Down
5 changes: 3 additions & 2 deletions src/filters-downloader-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const FiltersDownloaderCreator = (FileDownloadWrapper: IFileDownloader): IFilter
* @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.
* @param errorMessage The error message to include in the error message.
* @param originalError The error message to include in the error message.
* @throws {Error} Throws an error with a detailed error message.
*/
const throwError = (
Expand All @@ -263,7 +263,8 @@ const FiltersDownloaderCreator = (FileDownloadWrapper: IFileDownloader): IFilter
errorChunks.push(`\t${line}`);
}

if (errorMessage) {
if (originalError) {
const errorMessage = originalError instanceof Error ? originalError.message : String(originalError);
errorChunks.push(`\t${errorMessage}`);
}

Expand Down

0 comments on commit ddd9ac0

Please sign in to comment.