generated from boneskull/boneskull-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
814 additions
and
529 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
2 changes: 1 addition & 1 deletion
2
packages/midnight-smoker/src/error/aggregate-pkg-manager-error.ts
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
61 changes: 61 additions & 0 deletions
61
packages/midnight-smoker/src/error/aggregate-smoker-error.ts
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,61 @@ | ||
import {isZodError} from '#util/error-util'; | ||
import {castArray} from '#util/util'; | ||
import {fromZodError} from 'zod-validation-error'; | ||
import {BaseSmokerError, getErrorCode, type SmokerError} from './base-error'; | ||
import type {SmokerErrorCode, SmokerErrorId} from './codes'; | ||
|
||
/** | ||
* Base class for all aggregate exceptions thrown by `midnight-smoker`. | ||
* | ||
* This should only be used if _multiple_ errors are being collected--not just | ||
* catching some `Error` then throwing our own; use {@link BaseSmokerError} for | ||
* that. | ||
* | ||
* @template Context - Arbitrary per-exception-class data to attach to the | ||
* error. | ||
* @group Errors | ||
*/ | ||
|
||
export abstract class AggregateSmokerError<Context extends object | void = void> | ||
extends AggregateError | ||
implements SmokerError<Context> | ||
{ | ||
public override readonly cause?: void; | ||
|
||
public readonly context?: Context; | ||
|
||
public readonly code: SmokerErrorCode; | ||
|
||
public abstract readonly id: SmokerErrorId; | ||
|
||
/** | ||
* @privateRemarks | ||
* Why doesn't the {@link AggregateError} constructor set this value? | ||
*/ | ||
public override errors: Error[]; | ||
|
||
constructor(message: string, errors?: Error[] | Error, context?: Context) { | ||
const errs = castArray(errors).map((err) => | ||
isZodError(err) ? fromZodError(err) : err, | ||
); | ||
super(errs, message); | ||
this.context = context ?? undefined; | ||
this.errors = errs; | ||
this.code = getErrorCode(this); | ||
} | ||
|
||
public format(verbose = false) { | ||
return BaseSmokerError.prototype.format.call(this, verbose); | ||
} | ||
|
||
public toJSON() { | ||
return { | ||
message: this.message, | ||
id: this.id, | ||
stack: this.stack, | ||
context: this.context, | ||
code: this.code, | ||
errors: this.errors, | ||
}; | ||
} | ||
} |
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
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,30 @@ | ||
import {type StaticPkgManagerSpec} from '#schema/static-pkg-manager-spec'; | ||
import {type WorkspaceInfo} from '#schema/workspaces'; | ||
import {isString} from 'lodash'; | ||
import {BaseSmokerError} from './base-error'; | ||
|
||
/** | ||
* @group Errors | ||
*/ | ||
|
||
export class PackParseError extends BaseSmokerError< | ||
{ | ||
pkgManager: string; | ||
output: string; | ||
workspace: WorkspaceInfo; | ||
}, | ||
SyntaxError | ||
> { | ||
public readonly id = 'PackParseError'; | ||
|
||
constructor( | ||
message: string, | ||
pkgManager: string | StaticPkgManagerSpec, | ||
workspace: WorkspaceInfo, | ||
error: SyntaxError, | ||
output: string, | ||
) { | ||
const pmSpec = isString(pkgManager) ? pkgManager : pkgManager.spec; | ||
super(message, {pkgManager: pmSpec, output, workspace}, error); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,25 +1,20 @@ | ||
import type {StaticRuleContext} from '#schema/rule-static'; | ||
import {type LintManifest} from '#schema/lint-manifest'; | ||
import {type SomeRuleConfig} from '#schema/rule-options'; | ||
import {type Result} from '#schema/workspaces'; | ||
import {type Simplify} from 'type-fest'; | ||
import {BaseSmokerError} from './base-error'; | ||
|
||
export type RuleErrorContext = Simplify< | ||
Result<LintManifest> & { | ||
config: SomeRuleConfig; | ||
ruleId: string; | ||
} | ||
>; | ||
|
||
/** | ||
* @group Errors | ||
*/ | ||
|
||
export class RuleError extends BaseSmokerError< | ||
{ | ||
context: StaticRuleContext; | ||
ruleId: string; | ||
}, | ||
Error | ||
> { | ||
export class RuleError extends BaseSmokerError<RuleErrorContext, Error> { | ||
public readonly id = 'RuleError'; | ||
|
||
constructor( | ||
message: string, | ||
context: StaticRuleContext, | ||
ruleId: string, | ||
error: Error, | ||
) { | ||
super(message, {context, ruleId}, error); | ||
} | ||
} |
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,4 @@ | ||
import {type PackError} from './pack-error'; | ||
import {type PackParseError} from './pack-parse-error'; | ||
|
||
export type SomePackError = PackError | PackParseError; |
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
Oops, something went wrong.