snapshot of https://github.com/toeverything/AFFiNE.git (canary, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Build & Test / Analyze (javascript, blocksuite) (push) Failing after 3s
Build & Test / Rust test filter (push) Failing after 3s
Build & Test / E2E BlockSuite Test (2) (push) Failing after 3s
Build & Test / E2E BlockSuite Test (3) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (4) (push) Failing after 3s
Build & Test / E2E BlockSuite Cross Browser Test (push) Failing after 3s
Build & Test / E2E Mobile Test (1) (push) Failing after 3s
Build & Test / E2E Mobile Test (2) (push) Failing after 3s
Build & Test / Build AFFiNE native (x86_64-unknown-linux-gnu) (push) Failing after 4s
Build & Test / Unit Test (1) (push) Has been skipped
Build & Test / Unit Test (2) (push) Has been skipped
Build & Test / Unit Test (3) (push) Has been skipped
Build & Test / Build Server native (push) Failing after 3s
Build & Test / Check Git Status (push) Has been skipped
Build & Test / Server Test (0, 4) (push) Has been skipped
Build & Test / Server Test (1, 4) (push) Has been skipped
Build & Test / Analyze (javascript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, affine) (push) Failing after 3s
Build & Test / Analyze (typescript, blocksuite) (push) Failing after 3s
Build & Test / Mobile native build filter (push) Failing after 3s
Build & Test / Check yarn binary (push) Failing after 3s
Build & Test / E2E BlockSuite Test (1) (push) Failing after 4s
Build & Test / E2E BlockSuite Test (5) (push) Failing after 3s
Build & Test / Unit Test (4) (push) Has been skipped
Build & Test / Unit Test (5) (push) Has been skipped
Build & Test / Native Unit Test (push) Has been skipped
Build & Test / Server Test (2, 4) (push) Has been skipped
Build & Test / Server Test (3, 4) (push) Has been skipped
Build & Test / Server Test with Elasticsearch (push) Has been skipped
Build & Test / Server Test with Embedded Search (push) Has been skipped
Build & Test / Server Test with Manticore Search (push) Has been skipped
Build & Test / Server E2E Test (push) Has been skipped
Build & Test / Cloud Desktop E2E Test (push) Has been skipped
Build & Test / Cloud E2E Test 1/2 (push) Has been skipped
Build & Test / Cloud E2E Test 2/2 (push) Has been skipped
Build & Test / Build @affine/electron renderer (push) Failing after 3s
Build & Test / Copilot test filter (push) Failing after 4s
Build & Test / Lint Rust (push) Has been skipped
Build & Test / Build Android app (push) Has been skipped
Build & Test / Test Android app (push) Has been skipped
Build & Test / Run native tests (push) Has been skipped
Build & Test / Server Copilot Api Test (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (3, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (4, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (1, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (2, 5) (push) Has been skipped
Build & Test / Frontend Copilot E2E Test (5, 5) (push) Has been skipped
Build & Test / Desktop Test (ubuntu-latest, linux, x64, x86_64-unknown-linux-gnu, true) (push) Has been cancelled
Build & Test / Desktop Test (windows-latest, windows, x64, x86_64-pc-windows-msvc, true) (push) Has been cancelled
Build & Test / 3, 2, 1 Launch (push) Has been cancelled
Build & Test / Lint (push) Has been cancelled
Build & Test / Typecheck (push) Has been cancelled
Build & Test / Build iOS app (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-apple-darwin) (push) Has been cancelled
Build & Test / E2E Test (1) (push) Has been cancelled
Build & Test / E2E Test (2) (push) Has been cancelled
Build & Test / E2E Test (3) (push) Has been cancelled
Build & Test / E2E Test (4) (push) Has been cancelled
Build & Test / E2E Test (5) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-apple-darwin) (push) Has been cancelled
Build & Test / Build AFFiNE native (aarch64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Build AFFiNE native (x86_64-pc-windows-msvc) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, arm64, aarch64-apple-darwin, true) (push) Has been cancelled
Build & Test / Desktop Test (macos-latest, macos, x64, x86_64-apple-darwin, false) (push) Has been cancelled

This commit is contained in:
upstream-mirror
2026-09-16 00:31:07 +05:00
commit 50f788e799
7907 changed files with 988785 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# @affine/error
AFFiNE error handler utilities

View File

@@ -0,0 +1,16 @@
{
"name": "@affine/error",
"version": "0.27.5",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts"
},
"peerDependencies": {
"@affine/graphql": "workspace:*",
"graphql": "^16.9.0"
},
"devDependencies": {
"vitest": "^4.1.8"
}
}

View File

@@ -0,0 +1,102 @@
import { describe, expect, it } from 'vitest';
import { GraphQLError, UserFriendlyError } from '..';
describe('user friendly error', () => {
it('should create from graphql error', () => {
const gqlError = new GraphQLError('test', {
extensions: {
status: 400,
code: 'BAD_REQUEST',
type: 'BAD_REQUEST',
name: 'SOME_ERROR_NAME',
message: 'test',
},
});
const error = UserFriendlyError.fromAny(gqlError);
expect(error.name).toBe('SOME_ERROR_NAME');
expect(error.status).toBe(400);
expect(error.code).toBe('BAD_REQUEST');
expect(error.type).toBe('BAD_REQUEST');
expect(error.message).toBe('test');
});
it('should create from any error', () => {
const error = UserFriendlyError.fromAny(new Error('test'));
expect(error.message).toBe('test');
});
it('should create from object', () => {
const error = UserFriendlyError.fromAny({
name: 'SOME_ERROR_NAME',
status: 400,
code: 'BAD_REQUEST',
type: 'BAD_REQUEST',
message: 'test',
});
expect(error.message).toBe('test');
});
it('should create from string', () => {
const error = UserFriendlyError.fromAny('test error');
expect(error.message).toBe('test error');
});
it('should create fallback error', () => {
const error = UserFriendlyError.fromAny(null);
expect(error.message).toBe(
'Unhandled error raised. Please contact us for help.'
);
});
it('should test network error', () => {
const error = UserFriendlyError.fromAny({
name: 'NETWORK_ERROR',
status: 500,
code: 'INTERNAL_SERVER_ERROR',
type: 'INTERNAL_SERVER_ERROR',
message: 'test',
});
expect(error.isNetworkError()).toBe(true);
const error2 = UserFriendlyError.fromAny({
name: 'SOME_ERROR_NAME',
status: 400,
code: 'BAD_REQUEST',
type: 'BAD_REQUEST',
message: 'test',
});
expect(error2.isNetworkError()).toBe(false);
});
it('should test name', () => {
const error = UserFriendlyError.fromAny({
name: 'SOME_ERROR_NAME',
status: 400,
code: 'BAD_REQUEST',
type: 'BAD_REQUEST',
message: 'test',
});
// @ts-expect-error test name
expect(error.is('SOME_ERROR_NAME')).toBe(true);
});
it('should test status', () => {
const error = UserFriendlyError.fromAny({
name: 'SOME_ERROR_NAME',
status: 400,
code: 'BAD_REQUEST',
type: 'BAD_REQUEST',
message: 'test',
});
expect(error.isStatus(400)).toBe(true);
});
});

View File

@@ -0,0 +1,110 @@
import type { ErrorDataUnion, ErrorNames } from '@affine/graphql';
import { GraphQLError as BaseGraphQLError } from 'graphql';
export type ErrorName =
| keyof typeof ErrorNames
| 'NETWORK_ERROR'
| 'CONTENT_TOO_LARGE'
| 'REQUEST_ABORTED'
| 'UNSUPPORTED_SERVER_VERSION';
export interface UserFriendlyErrorResponse {
status: number;
code: string;
type: string;
name: ErrorName;
message: string;
data?: any;
stacktrace?: string;
}
function UnknownError(message: string) {
return new UserFriendlyError({
status: 500,
code: 'INTERNAL_SERVER_ERROR',
type: 'INTERNAL_SERVER_ERROR',
name: 'INTERNAL_SERVER_ERROR',
message,
});
}
type ToPascalCase<S extends string> = S extends `${infer A}_${infer B}`
? `${Capitalize<Lowercase<A>>}${ToPascalCase<B>}`
: Capitalize<Lowercase<S>>;
export type ErrorData = {
[K in ErrorNames]: Extract<
ErrorDataUnion,
{ __typename?: `${ToPascalCase<K>}DataType` }
>;
};
export class GraphQLError extends BaseGraphQLError {
// @ts-expect-error better to be a known type without any type casting
override extensions!: UserFriendlyErrorResponse;
}
export class UserFriendlyError
extends Error
implements UserFriendlyErrorResponse
{
readonly status = this.response.status;
readonly code = this.response.code;
readonly type = this.response.type;
override readonly name = this.response.name;
override readonly message = this.response.message;
readonly data = this.response.data;
readonly stacktrace = this.response.stacktrace;
static fromAny(anything: any) {
if (anything instanceof UserFriendlyError) {
return anything;
}
switch (typeof anything) {
case 'string':
return UnknownError(anything);
case 'object': {
if (anything) {
if (anything instanceof GraphQLError) {
return new UserFriendlyError(anything.extensions);
} else if (anything.type && anything.name && anything.message) {
return new UserFriendlyError(anything);
} else if (anything.message) {
return UnknownError(anything.message);
}
}
}
}
return UnknownError('Unhandled error raised. Please contact us for help.');
}
constructor(private readonly response: UserFriendlyErrorResponse) {
super(response.message);
}
is(name: ErrorName) {
return this.name === name;
}
isStatus(status: number) {
return this.status === status;
}
static isNetworkError(error: UserFriendlyError) {
return error.name === 'NETWORK_ERROR';
}
static notNetworkError(error: UserFriendlyError) {
return !UserFriendlyError.isNetworkError(error);
}
isNetworkError() {
return UserFriendlyError.isNetworkError(this);
}
notNetworkError() {
return UserFriendlyError.notNetworkError(this);
}
}

View File

@@ -0,0 +1,10 @@
{
"extends": "../../../tsconfig.web.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo"
},
"include": ["./src"],
"references": []
}