Skip to content

Commit cf9d891

Browse files
fix: adding warning when pushing monitors from yaml files (#977)
* package.json - added dependency 'utf-8-validate' * monitor.ts - Added validation and warnings - Validation/warning prior to UTF-8 decoding of files - warning when a 'browser' type monitor is ignored - removing unused variable (causing linter error) * Update src/push/monitor.ts changing warning text Co-authored-by: Vignesh Shanmugam <vignesh.shanmugam22@gmail.com> * src/push/monitor.ts - using node standard libarary to test utf-8 encoding - updated types@node to be more in line with current version * Update src/push/monitor.ts - updating warning message. Co-authored-by: Vignesh Shanmugam <vignesh.shanmugam22@gmail.com> * fix node type and message --------- Co-authored-by: Vignesh Shanmugam <vignesh.shanmugam22@gmail.com>
1 parent 79fe27d commit cf9d891

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

package-lock.json

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"@types/babel__code-frame": "^7.0.3",
8282
"@types/jest": "^28.1.8",
8383
"@types/micromatch": "^4.0.9",
84-
"@types/node": "^16.11.59",
84+
"@types/node": "^18.19.63",
8585
"@types/semver": "^7",
8686
"@types/stack-utils": "^2.0.1",
8787
"@typescript-eslint/eslint-plugin": "^5.38.0",

src/push/monitor.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { extname, join } from 'path';
2828
import { LineCounter, parseDocument, Document, YAMLSeq, YAMLMap } from 'yaml';
2929
import { bold, red } from 'kleur/colors';
3030
import { Bundler } from './bundler';
31+
import NodeBuffer from 'node:buffer';
3132
import { SYNTHETICS_PATH, totalist, indent, warn } from '../helpers';
3233
import { LocationsMap } from '../locations/public-locations';
3334
import {
@@ -184,7 +185,13 @@ export async function createLightweightMonitors(
184185
let warnOnce = false;
185186
const monitors: Monitor[] = [];
186187
for (const file of lwFiles.values()) {
187-
const content = await readFile(file, 'utf-8');
188+
// First check encoding and warn if any files are not the correct encoding.
189+
const bufferContent = await readFile(file);
190+
const isUtf8 = NodeBuffer.isUtf8(bufferContent);
191+
if (!isUtf8) {
192+
warn(`${file} is not UTF-8 encoded. Monitors might be skipped.`);
193+
}
194+
const content = bufferContent.toString('utf-8');
188195
const lineCounter = new LineCounter();
189196
const parsedDoc = parseDocument(content, {
190197
lineCounter,
@@ -218,6 +225,9 @@ export async function createLightweightMonitors(
218225
const monitor = mergedConfig[i];
219226
// Skip browser monitors from the YML files
220227
if (monitor['type'] === 'browser') {
228+
warn(
229+
`Browser monitors from ${file} are skipped.`
230+
);
221231
continue;
222232
}
223233
const { line, col } = lineCounter.linePos(offsets[i]);

0 commit comments

Comments
 (0)