Skip to content

Commit

Permalink
monitor.ts - Added validation and warnings
Browse files Browse the repository at this point in the history
- Validation/warning prior to UTF-8 decoding of files
- warning when a 'browser' type monitor is ignored
- removing unused variable (causing linter error)
  • Loading branch information
Joe Gast committed Oct 31, 2024
1 parent 8e1d65c commit f855a3c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/push/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { extname, join } from 'path';
import { LineCounter, parseDocument, Document, YAMLSeq, YAMLMap } from 'yaml';
import { bold, red } from 'kleur/colors';
import { Bundler } from './bundler';
import utf8Validate from 'utf-8-validate';
import { SYNTHETICS_PATH, totalist, indent, warn } from '../helpers';
import { LocationsMap } from '../locations/public-locations';
import {
Expand Down Expand Up @@ -184,7 +185,15 @@ export async function createLightweightMonitors(
let warnOnce = false;
const monitors: Monitor[] = [];
for (const file of lwFiles.values()) {
const content = await readFile(file, 'utf-8');
// First check encoding and warn if any files are not the correct encoding.
const bufferContent = await readFile(file);
const isUtf8 = utf8Validate(bufferContent);
if (!isUtf8) {
warn(
`file ${file} is not encoded in utf-8. utf-8 encoding is expected. Monitor configurations in this file may be ignored.`
);
}
const content = bufferContent.toString('utf-8');
const lineCounter = new LineCounter();
const parsedDoc = parseDocument(content, {
lineCounter,
Expand Down Expand Up @@ -218,6 +227,9 @@ export async function createLightweightMonitors(
const monitor = mergedConfig[i];
// Skip browser monitors from the YML files
if (monitor['type'] === 'browser') {
warn(
`a monitor with type 'browser' was detected in file ${file}. 'browser type monitors are not supported. Monitor will be skipped.`
);
continue;
}
const { line, col } = lineCounter.linePos(offsets[i]);
Expand Down

0 comments on commit f855a3c

Please sign in to comment.