• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

streetsidesoftware / cspell / 12457971703

22 Dec 2024 09:54PM UTC coverage: 93.54% (-0.5%) from 94.057%
12457971703

Pull #6702

github

web-flow
Merge 729f6b53a into 3d16857fe
Pull Request #6702: fix: reduce size when bundled

11604 of 13369 branches covered (86.8%)

15147 of 16193 relevant lines covered (93.54%)

30926.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/packages/cspell-io/src/node/file/FetchError.ts
1
export class FetchUrlError extends Error implements NodeJS.ErrnoException {
×
2
    constructor(
3
        message: string,
4
        readonly code: string | undefined,
18✔
5
        readonly status: number | undefined,
18✔
6
        readonly url: URL,
18✔
7
    ) {
8
        super(message);
18✔
9
        this.name = 'FetchUrlError';
18✔
10
    }
11

12
    static create(url: URL, status: number, message?: string): FetchUrlError {
13
        if (status === 404) return new FetchUrlError(message || 'URL not found.', 'ENOENT', status, url);
8✔
14
        if (status >= 400 && status < 500)
5✔
15
            return new FetchUrlError(message || 'Permission denied.', 'EACCES', status, url);
2✔
16
        return new FetchUrlError(message || 'Fatal Error', 'ECONNREFUSED', status, url);
3✔
17
    }
18

19
    static fromError(url: URL, e: Error): FetchUrlError {
20
        const cause = getCause(e);
9✔
21
        if (cause) {
9✔
22
            return new FetchUrlError(cause.message, cause.code, undefined, url);
4✔
23
        }
24
        if (isNodeError(e)) {
5✔
25
            return new FetchUrlError(e.message, e.code, undefined, url);
1✔
26
        }
27
        return new FetchUrlError(e.message, undefined, undefined, url);
4✔
28
    }
29
}
30

31
export function isNodeError(e: unknown): e is NodeJS.ErrnoException {
32
    if (e instanceof Error && 'code' in e && typeof e.code === 'string') return true;
9✔
33
    if (e && typeof e === 'object' && 'code' in e && typeof e.code === 'string') return true;
5✔
34
    return false;
4✔
35
}
36

37
export function isError(e: unknown): e is Error {
38
    return e instanceof Error;
9✔
39
}
40

41
interface ErrorWithOptionalCause extends Error {
42
    cause?: NodeJS.ErrnoException;
43
}
44

45
export function isErrorWithOptionalCause(e: unknown): e is ErrorWithOptionalCause {
46
    return isError(e) && (!('cause' in e) || isNodeError(e.cause) || isNodeError(e));
9!
47
}
48

49
export function getCause(e: unknown): NodeJS.ErrnoException | undefined {
50
    return isErrorWithOptionalCause(e) ? e.cause : undefined;
9!
51
}
52

53
export function toFetchUrlError(err: unknown, url: URL): FetchUrlError {
54
    return err instanceof FetchUrlError ? err : FetchUrlError.fromError(url, toError(err));
10✔
55
}
56

57
export function toError(err: unknown): Error {
58
    return err instanceof Error ? err : new Error('Unknown Error', { cause: err });
8✔
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc