From 7cd3b95317c4d9263e514f33589cb359766d463b Mon Sep 17 00:00:00 2001 From: Taylor Mullen Date: Fri, 18 Apr 2025 13:37:51 -0400 Subject: Fix linting errors in a number of core and tool files (partial) - As part of this work I also started building out errors.ts which will be a cumulation of error helpers to better handle the challenging `catch (error: unknown)` requirement. - More changes are to come, this is truly a partial change in order to not disrupt as many people as possible. Part of https://b.corp.google.com/issues/411384603 --- packages/cli/src/utils/errors.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 packages/cli/src/utils/errors.ts (limited to 'packages/cli/src/utils') diff --git a/packages/cli/src/utils/errors.ts b/packages/cli/src/utils/errors.ts new file mode 100644 index 00000000..7708895a --- /dev/null +++ b/packages/cli/src/utils/errors.ts @@ -0,0 +1,18 @@ +export function isNodeError(error: unknown): error is NodeJS.ErrnoException { + return error instanceof Error && 'code' in error; +} + +export function getErrorMessage(error: unknown): string { + if (error instanceof Error) { + return error.message; + } else { + // Attempt to convert the non-Error value to a string for logging + try { + const errorMessage = String(error); + return errorMessage; + } catch { + // If String() itself fails (highly unlikely) + return 'Failed to get error details'; + } + } +} \ No newline at end of file -- cgit v1.2.3