Skip to content

Commit

Permalink
fix: adding warning when pushing monitors from yaml files (#977)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Spoonsk and vigneshshanmugam authored Nov 1, 2024
1 parent 79fe27d commit cf9d891
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
19 changes: 14 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@types/babel__code-frame": "^7.0.3",
"@types/jest": "^28.1.8",
"@types/micromatch": "^4.0.9",
"@types/node": "^16.11.59",
"@types/node": "^18.19.63",
"@types/semver": "^7",
"@types/stack-utils": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^5.38.0",
Expand Down
12 changes: 11 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 NodeBuffer from 'node:buffer';
import { SYNTHETICS_PATH, totalist, indent, warn } from '../helpers';
import { LocationsMap } from '../locations/public-locations';
import {
Expand Down Expand Up @@ -184,7 +185,13 @@ 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 = NodeBuffer.isUtf8(bufferContent);
if (!isUtf8) {
warn(`${file} is not UTF-8 encoded. Monitors might be skipped.`);
}
const content = bufferContent.toString('utf-8');
const lineCounter = new LineCounter();
const parsedDoc = parseDocument(content, {
lineCounter,
Expand Down Expand Up @@ -218,6 +225,9 @@ export async function createLightweightMonitors(
const monitor = mergedConfig[i];
// Skip browser monitors from the YML files
if (monitor['type'] === 'browser') {
warn(
`Browser monitors from ${file} are skipped.`
);
continue;
}
const { line, col } = lineCounter.linePos(offsets[i]);
Expand Down

0 comments on commit cf9d891

Please sign in to comment.