summaryrefslogtreecommitdiff
path: root/packages/server/src/utils/errors.ts
blob: 15417c835d5880c49436deeaab8e4052a8bf1db2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

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';
    }
  }
}