Skip to content

Commit 43a31d3

Browse files
committed
chore:update all QiankunError usage
1 parent 15f7ef2 commit 43a31d3

File tree

14 files changed

+117
-11
lines changed

14 files changed

+117
-11
lines changed

.dumi/pages/error/codes/2.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import CodeSnippet from '../CodeSnippet'
3+
4+
export default function ErrorCode1(props) {
5+
return (
6+
<>
7+
<h1>#2: You should not set multiply entry script in one entry html, but {props.getErrorCodeArg(0)} has at least 2 entry scripts</h1>
8+
</>
9+
)
10+
}

.dumi/pages/error/codes/3.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import CodeSnippet from '../CodeSnippet'
3+
4+
export default function ErrorCode1(props) {
5+
return (
6+
<>
7+
<h1>#3: entry {props.getErrorCodeArg(0)} load failed as entry script {props.getErrorCodeArg(1)} load failed</h1>
8+
</>
9+
)
10+
}

.dumi/pages/error/codes/4.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import CodeSnippet from '../CodeSnippet'
3+
4+
export default function ErrorCode1(props) {
5+
return (
6+
<>
7+
<h1>#4: entry {props.getErrorCodeArg(0)} response body is empty!</h1>
8+
</>
9+
)
10+
}

.dumi/pages/error/codes/5.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import CodeSnippet from '../CodeSnippet'
3+
4+
export default function ErrorCode1(props) {
5+
return (
6+
<>
7+
<h1>#5: {props.getErrorCodeArg(0)} entry {props.getErrorCodeArg(1)} load failed as it not export lifecycles</h1>
8+
</>
9+
)
10+
}

.dumi/pages/error/codes/6.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import CodeSnippet from '../CodeSnippet'
3+
4+
export default function ErrorCode1(props) {
5+
return (
6+
<>
7+
<h1>#6: You need to export lifecycle functions in {props.getErrorCodeArg(0)} entry</h1>
8+
</>
9+
)
10+
}

.dumi/pages/error/codes/7.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import CodeSnippet from '../CodeSnippet'
3+
4+
export default function ErrorCode1(props) {
5+
return (
6+
<>
7+
<h1>#7: {props.getErrorCodeArg(0)} head element not existed while accessing document.head!</h1>
8+
</>
9+
)
10+
}

.dumi/pages/error/codes/8.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import CodeSnippet from '../CodeSnippet'
3+
4+
export default function ErrorCode1(props) {
5+
return (
6+
<>
7+
<h1>#8: {props.getErrorCodeArg(0)} container {props.getErrorCodeArg(1)} element not ready while rebuilding!</h1>
8+
</>
9+
)
10+
}

.dumi/pages/error/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function CodeSnippet() {
2020
getErrorCodeArg={getErrorCodeArg}
2121
errorCode={code} />
2222
</div>
23-
) : (<div>请输入错误码code</div>)
23+
) : (<div>Please enter the error code</div>)
2424

2525
function getErrorCodeArg(index, argName) {
2626
const missingArg = argName ? `(${argName})` : `(unknown)`;

packages/loader/src/index.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ export async function loadEntry<T>(entry: Entry, container: HTMLElement, opts: L
121121
if (isEntryScript(script)) {
122122
if (foundEntryScript) {
123123
throw new QiankunError(
124+
2,
124125
`You should not set multiply entry script in one entry html, but ${entry} has at least 2 entry scripts`,
126+
entry,
125127
);
126128
}
127129

@@ -139,7 +141,12 @@ export async function loadEntry<T>(entry: Entry, container: HTMLElement, opts: L
139141
onEntryLoaded();
140142
} else {
141143
entryScriptLoadedDeferred.reject(
142-
new QiankunError(`entry ${entry} load failed as entry script ${script.src} load failed}`),
144+
new QiankunError(
145+
3,
146+
`entry ${entry} load failed as entry script ${script.src} load failed`,
147+
entry,
148+
script.src,
149+
),
143150
);
144151
}
145152
}
@@ -171,5 +178,5 @@ export async function loadEntry<T>(entry: Entry, container: HTMLElement, opts: L
171178
return entryScriptLoadedDeferred.promise;
172179
}
173180

174-
throw new QiankunError(`entry ${entry} response body is empty!`);
181+
throw new QiankunError(4, `entry ${entry} response body is empty!`, entry);
175182
}

packages/qiankun/src/core/loadApp.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { moduleResolver as defaultModuleResolver, transpileAssets, wrapFetchWith
1010
import { concat, isFunction, mergeWith } from 'lodash';
1111
import type { ParcelConfigObject } from 'single-spa';
1212
import getAddOns from '../addons';
13-
import { QiankunError } from '../error';
13+
import { QiankunError } from '@qiankunjs/shared';
1414
import type { AppConfiguration, LifeCycleFn, LifeCycles, LoadableApp, MicroAppLifeCycles, ObjectType } from '../types';
1515
import {
1616
getPureHTMLStringWithoutScripts,
@@ -94,7 +94,8 @@ export default async function loadApp<T extends ObjectType>(
9494
await execHooksChain(toArray(beforeLoad), app, global);
9595

9696
const lifecycles = await lifecyclesPromise;
97-
if (!lifecycles) throw new QiankunError(`${appName} entry ${entry} load failed as it not export lifecycles`);
97+
if (!lifecycles)
98+
throw new QiankunError(5, `${appName} entry ${entry} load failed as it not export lifecycles`, appName, entry);
9899
const { bootstrap, mount, unmount, update } = getLifecyclesFromExports(
99100
lifecycles,
100101
appName,
@@ -235,7 +236,7 @@ function getLifecyclesFromExports(
235236
return globalVariableExports;
236237
}
237238

238-
throw new QiankunError(`You need to export lifecycle functions in ${appName} entry`);
239+
throw new QiankunError(6, `You need to export lifecycle functions in ${appName} entry`, appName);
239240
}
240241

241242
function calcPublicPath(entry: string): string {

packages/qiankun/src/error.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
export class QiankunError extends Error {
2-
constructor(message: string) {
3-
super(`[qiankun]: ${message}`);
2+
constructor(code: number, message: string, ...args: string[]) {
3+
let errorMessage = `[qiankun #${code}]: ${message ? message + ' ' : ''}`;
4+
if (process.env.NODE_ENV === 'production') {
5+
errorMessage += `See https://qiankun.umijs.org/error/?code=${code}${
6+
args.length ? `&arg=${args.join('&arg=')}` : ''
7+
}`;
8+
} else {
9+
console.warn('args', ...args);
10+
}
11+
super(errorMessage);
412
}
513
}

packages/sandbox/src/patchers/dynamicAppend/forStandardSandbox.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ function patchDocument(sandbox: Sandbox, getContainer: () => HTMLElement): Calla
7878
const container = getContainer();
7979
const containerHeadElement = getContainerHeadElement(container);
8080
if (!containerHeadElement) {
81-
throw new QiankunError(`${sandbox.name} head element not existed while accessing document.head!`);
81+
throw new QiankunError(
82+
7,
83+
`${sandbox.name} head element not existed while accessing document.head!`,
84+
sandbox.name,
85+
);
8286
}
8387
return containerHeadElement;
8488
};
@@ -374,7 +378,10 @@ export function patchStandardSandbox(
374378
const containerHeadElement = getContainerHeadElement(container);
375379
if (!containerHeadElement) {
376380
throw new QiankunError(
381+
8,
377382
`${appName} container ${qiankunHeadTagName} element not ready while rebuilding!`,
383+
appName,
384+
qiankunHeadTagName,
378385
);
379386
}
380387
return containerHeadElement;
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export class QiankunError extends Error {
2+
constructor(code: number, message: string, ...args: string[]) {
3+
let errorMessage = `[qiankun #${code}]: ${message ? message + ' ' : ''}`;
4+
if (process.env.NODE_ENV === 'production') {
5+
errorMessage += `See https://qiankun.umijs.org/error/?code=${code}${
6+
args.length ? `&arg=${args.join('&arg=')}` : ''
7+
}`;
8+
} else {
9+
console.warn('args', ...args);
10+
}
11+
super(errorMessage);
12+
}
13+
}

packages/shared/src/reporter/QiankunError.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export class QiankunError extends Error {
2-
constructor(message: string, code?: number, ...args: string[]) {
2+
constructor(code: number, message: string, ...args: string[]) {
33
let errorMessage = `[qiankun #${code}]: ${message ? message + ' ' : ''}`;
4-
if (process.env.NODE_ENV === 'production' && typeof(code) !== 'undefined') {
4+
if (process.env.NODE_ENV === 'production') {
55
errorMessage += `See https://qiankun.umijs.org/error/?code=${code}${
66
args.length ? `&arg=${args.join('&arg=')}` : ''
77
}`;

0 commit comments

Comments
 (0)