-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: cleaning up main and moving stuff around
- Loading branch information
1 parent
d9811c7
commit 54a78f0
Showing
5 changed files
with
45 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { writeFile } from 'fs/promises'; | ||
import { ProblemError } from '@snyk/error-catalog-nodejs-public'; | ||
|
||
// TODO: handle more gracefully | ||
const ERROR_FILE_PATH = process.env.SNYK_ERR_FILE!; | ||
|
||
export async function sendError(err: Error): Promise<void> { | ||
const data = serializeError(err); | ||
return await writeFile(ERROR_FILE_PATH, data); | ||
} | ||
|
||
// TBD: json format that the erorr get sent as (ProblemErrorJson, JSON API, custom one?) | ||
function serializeError(err: Error): string { | ||
// @ts-expect-error Using this instead of 'instanceof' since the error might be caught from external CLI plugins. | ||
// See: https://github.com/snyk/error-catalog/blob/main/packages/error-catalog-nodejs/src/problem-error.ts#L17-L19 | ||
if (err.isErrorCatalogError) { | ||
// NOTE: there's also the JSON API version for this. | ||
return JSON.stringify((err as ProblemError).toProblemJson('instance?')); | ||
} | ||
|
||
return JSON.stringify(err, Object.getOwnPropertyNames(err)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters