66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
/**
|
|
* Base error class for smartupdate errors
|
|
*/
|
|
export class SmartUpdateError extends Error {
|
|
constructor(message: string) {
|
|
super(message);
|
|
this.name = 'SmartUpdateError';
|
|
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, this.constructor);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when the npm registry is unavailable
|
|
*/
|
|
export class RegistryUnavailableError extends SmartUpdateError {
|
|
constructor(message: string = 'Failed to retrieve package information from npm registry') {
|
|
super(message);
|
|
this.name = 'RegistryUnavailableError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when a package is not found in the registry
|
|
*/
|
|
export class PackageNotFoundError extends SmartUpdateError {
|
|
public readonly packageName: string;
|
|
|
|
constructor(packageName: string) {
|
|
super(`Package '${packageName}' not found in npm registry`);
|
|
this.name = 'PackageNotFoundError';
|
|
this.packageName = packageName;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when a version string is invalid
|
|
*/
|
|
export class InvalidVersionError extends SmartUpdateError {
|
|
public readonly version: string;
|
|
|
|
constructor(version: string, reason?: string) {
|
|
const message = reason
|
|
? `Invalid version string '${version}': ${reason}`
|
|
: `Invalid version string '${version}'`;
|
|
super(message);
|
|
this.name = 'InvalidVersionError';
|
|
this.version = version;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Error thrown when package name validation fails
|
|
*/
|
|
export class InvalidPackageNameError extends SmartUpdateError {
|
|
public readonly packageName: string;
|
|
|
|
constructor(packageName: string) {
|
|
super(`Invalid package name '${packageName}'. Package names must follow npm naming conventions.`);
|
|
this.name = 'InvalidPackageNameError';
|
|
this.packageName = packageName;
|
|
}
|
|
}
|