Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: yaml resource exhaustion #5127

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shaggy-dolphins-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperlane-xyz/cli": patch
---

Fix yaml resource exhaustion
12 changes: 10 additions & 2 deletions typescript/cli/src/utils/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import {
DocumentOptions,
LineCounter,
ParseOptions,
SchemaOptions,
ToJSOptions,
parse,
parse as yamlParse,
stringify as yamlStringify,
} from 'yaml';

import { objMerge } from '@hyperlane-xyz/utils';

import { log } from '../logger.js';

const yamlParse = (
content: string,
options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions,
) => parse(content, { maxAliasCount: -1, ...options });

export const MAX_READ_LINE_OUTPUT = 250;

export type FileFormat = 'yaml' | 'json';
Expand Down Expand Up @@ -250,7 +258,7 @@ export function logYamlIfUnderMaxLines(
): void {
const asYamlString = yamlStringify(obj, null, margin);
const lineCounter = new LineCounter();
parse(asYamlString, { lineCounter });
yamlParse(asYamlString, { lineCounter });

log(lineCounter.lineStarts.length < maxLines ? asYamlString : '');
}
Loading