diff options
| author | 2023-04-28 01:36:44 +0800 | |
|---|---|---|
| committer | 2023-04-28 01:36:44 +0800 | |
| commit | dd84b9d64fb98746a230cd24233ff50a562c39c9 (patch) | |
| tree | b583261ef00b3afe72ec4d6dacb31e57779a6faf /packages/turbo-ignore/src/errors.ts | |
| parent | 0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff) | |
| download | HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip | |
Diffstat (limited to 'packages/turbo-ignore/src/errors.ts')
| -rw-r--r-- | packages/turbo-ignore/src/errors.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/packages/turbo-ignore/src/errors.ts b/packages/turbo-ignore/src/errors.ts new file mode 100644 index 0000000..f600dfb --- /dev/null +++ b/packages/turbo-ignore/src/errors.ts @@ -0,0 +1,43 @@ +import { NonFatalErrorKey, NonFatalErrors } from "./types"; + +export const NON_FATAL_ERRORS: NonFatalErrors = { + MISSING_LOCKFILE: { + regex: + /reading (yarn.lock|package-lock.json|pnpm-lock.yaml):.*?no such file or directory/, + message: `turbo-ignore could not complete - no lockfile found, please commit one to your repository`, + }, + NO_PACKAGE_MANAGER: { + regex: + /run failed: We did not detect an in-use package manager for your project/, + message: `turbo-ignore could not complete - no package manager detected, please commit a lockfile, or set "packageManager" in your root "package.json"`, + }, + UNREACHABLE_PARENT: { + regex: /failed to resolve packages to run: commit HEAD\^ does not exist/, + message: `turbo-ignore could not complete - parent commit does not exist or is unreachable`, + }, + UNREACHABLE_COMMIT: { + regex: /commit \S+ does not exist/, + message: `turbo-ignore could not complete - commit does not exist or is unreachable`, + }, +}; + +export function shouldWarn({ err }: { err: string }): { + level: "warn" | "error"; + message: string; + code: NonFatalErrorKey | "UNKNOWN_ERROR"; +} { + const knownError = Object.keys(NON_FATAL_ERRORS).find((key) => { + const { regex } = NON_FATAL_ERRORS[key as NonFatalErrorKey]; + return regex.test(err); + }); + + if (knownError) { + return { + level: "warn", + message: NON_FATAL_ERRORS[knownError as NonFatalErrorKey].message, + code: knownError as NonFatalErrorKey, + }; + } + + return { level: "error", message: err, code: "UNKNOWN_ERROR" }; +} |
