Skip to content

Commit b4d820d

Browse files
committed
Rename coverError to wrapError
1 parent 35f5085 commit b4d820d

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

src/fs.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
readJsonObjectFile as underlyingReadJsonObjectFile,
44
writeJsonFile as underlyingWriteJsonFile,
55
} from '@metamask/action-utils';
6-
import { coverError, isErrorWithCode } from './misc-utils';
6+
import { wrapError, isErrorWithCode } from './misc-utils';
77

88
/**
99
* Reads the file at the given path, assuming its content is encoded as UTF-8.
@@ -16,7 +16,7 @@ export async function readFile(filePath: string): Promise<string> {
1616
try {
1717
return await fs.promises.readFile(filePath, 'utf8');
1818
} catch (error) {
19-
throw coverError(`Could not read file '${filePath}'`, error);
19+
throw wrapError(`Could not read file '${filePath}'`, error);
2020
}
2121
}
2222

@@ -34,7 +34,7 @@ export async function writeFile(
3434
try {
3535
await fs.promises.writeFile(filePath, content);
3636
} catch (error) {
37-
throw coverError(`Could not write file '${filePath}'`, error);
37+
throw wrapError(`Could not write file '${filePath}'`, error);
3838
}
3939
}
4040

@@ -56,7 +56,7 @@ export async function readJsonObjectFile(
5656
try {
5757
return await underlyingReadJsonObjectFile(filePath);
5858
} catch (error) {
59-
throw coverError(`Could not read JSON file '${filePath}'`, error);
59+
throw wrapError(`Could not read JSON file '${filePath}'`, error);
6060
}
6161
}
6262

@@ -77,7 +77,7 @@ export async function writeJsonFile(
7777
try {
7878
await underlyingWriteJsonFile(filePath, jsonValue);
7979
} catch (error) {
80-
throw coverError(`Could not write JSON file '${filePath}'`, error);
80+
throw wrapError(`Could not write JSON file '${filePath}'`, error);
8181
}
8282
}
8383

@@ -97,10 +97,7 @@ export async function fileExists(entryPath: string): Promise<boolean> {
9797
return false;
9898
}
9999

100-
throw coverError(
101-
`Could not determine if file exists '${entryPath}'`,
102-
error,
103-
);
100+
throw wrapError(`Could not determine if file exists '${entryPath}'`, error);
104101
}
105102
}
106103

@@ -118,7 +115,7 @@ export async function ensureDirectoryPathExists(
118115
try {
119116
return await fs.promises.mkdir(directoryPath, { recursive: true });
120117
} catch (error) {
121-
throw coverError(
118+
throw wrapError(
122119
`Could not create directory path '${directoryPath}'`,
123120
error,
124121
);
@@ -136,6 +133,6 @@ export async function removeFile(filePath: string): Promise<void> {
136133
try {
137134
return await fs.promises.rm(filePath, { force: true });
138135
} catch (error) {
139-
throw coverError(`Could not remove file '${filePath}'`, error);
136+
throw wrapError(`Could not remove file '${filePath}'`, error);
140137
}
141138
}

src/misc-utils.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
isErrorWithCode,
55
isErrorWithMessage,
66
isErrorWithStack,
7-
coverError,
7+
wrapError,
88
resolveExecutable,
99
getStdoutFromCommand,
1010
runCommand,
@@ -80,10 +80,10 @@ describe('misc-utils', () => {
8080
});
8181
});
8282

83-
describe('coverError', () => {
83+
describe('wrapError', () => {
8484
it('returns a new Error that links to the given Error', () => {
8585
const originalError = new Error('oops');
86-
const newError = coverError('Some message', originalError);
86+
const newError = wrapError('Some message', originalError);
8787

8888
expect(newError.message).toStrictEqual('Some message');
8989
expect(newError.cause).toBe(originalError);
@@ -92,13 +92,13 @@ describe('misc-utils', () => {
9292
it('copies over any "code" property that exists on the given Error', () => {
9393
const originalError: any = new Error('oops');
9494
originalError.code = 'CODE';
95-
const newError: any = coverError('Some message', originalError);
95+
const newError: any = wrapError('Some message', originalError);
9696

9797
expect(newError.code).toStrictEqual('CODE');
9898
});
9999

100100
it('returns a new Error which prefixes the given message', () => {
101-
const newError = coverError('Some message', 'Some original message');
101+
const newError = wrapError('Some message', 'Some original message');
102102

103103
expect(newError.message).toBe('Some message: Some original message');
104104
expect(newError.cause).toBeUndefined();

src/misc-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function isErrorWithStack(error: unknown): error is { stack: string } {
8080
* something throwable).
8181
* @returns A new error object.
8282
*/
83-
export function coverError(message: string, originalError: unknown) {
83+
export function wrapError(message: string, originalError: unknown) {
8484
if (isError(originalError)) {
8585
const error: any = new ErrorWithCause(message, { cause: originalError });
8686

src/release-specification.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { readFile } from './fs';
55
import {
66
debug,
77
hasProperty,
8-
coverError,
8+
wrapError,
99
isObject,
1010
runCommand,
1111
} from './misc-utils';
@@ -127,7 +127,7 @@ export async function waitForUserToEditReleaseSpecification(
127127
stdout.write('\r\u001B[K');
128128

129129
if (caughtError) {
130-
throw coverError(
130+
throw wrapError(
131131
'Encountered an error while waiting for the release spec to be edited.',
132132
caughtError,
133133
);
@@ -170,7 +170,7 @@ export async function validateReleaseSpecification(
170170
try {
171171
unvalidatedReleaseSpecification = YAML.parse(releaseSpecificationContents);
172172
} catch (error) {
173-
throw coverError(
173+
throw wrapError(
174174
[
175175
'Your release spec does not appear to be valid YAML.',
176176
afterwordForAllErrorMessages,

0 commit comments

Comments
 (0)