Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit

Permalink
Merge branch 'main' into next-merge-2023-12-23--00-16
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/release.yml
#	packages/client/src/TRPCClientError.ts
#	packages/server/src/shared/index.ts
#	tsconfig.build.json
  • Loading branch information
KATT committed Dec 22, 2023
2 parents e2c2ec0 + c6bf837 commit e6670f6
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 117 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/release-next.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Release next

on:
push:
branches: [main]

jobs:
next:
timeout-minutes: 10
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

name: Relase @next

runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: pnpm/action-setup@v2

- uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Check version
run: |
if [[ $(node -p "require('./packages/server/package.json').version.startsWith('10.')") != true ]]; then
echo "Error: The version in packages/server/package.json must start with '10.'"
exit 1
fi
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-trpc-${{ github.head_ref }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-trpc-${{ github.head_ref }}-
- name: Install deps (with cache)
run: pnpm --filter "@trpc/*" --filter root install

- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > $HOME/.npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- run: pnpm lerna publish --force-publish --canary major --preid alpha-$(pnpm --silent canary-preid) --dist-tag next --yes
24 changes: 6 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release canary

on:
push:
branches: [next]
branches: [main]

jobs:
canary:
Expand All @@ -11,14 +11,9 @@ jobs:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

name: Relase canary ${{ matrix.node }} and ${{ matrix.os }}
name: Relase nightly

runs-on: ${{ matrix.os }}

strategy:
matrix:
node: ['18.x']
os: [ubuntu-latest]
runs-on: ubuntu-latest

steps:
- name: Checkout repo
Expand All @@ -28,17 +23,10 @@ jobs:

- uses: pnpm/action-setup@v2

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
node-version: 20.x

- name: Check version
run: |
if [[ $(node -p "require('./packages/server/package.json').version.startsWith('10.')") != true ]]; then
echo "Error: The version in packages/server/package.json must start with '10.'"
exit 1
fi
- name: Get pnpm store directory
id: pnpm-cache
run: |
Expand All @@ -59,4 +47,4 @@ jobs:
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- run: pnpm lerna publish --force-publish --canary major --preid alpha-$(pnpm --silent canary-preid) --dist-tag next --yes
- run: pnpm lerna publish --force-publish --canary --preid alpha-$(pnpm --silent canary-preid) --dist-tag canary --yes
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-turbo": "^1.9.3",
"eslint-plugin-unicorn": "49.0.0",
"eslint-plugin-unicorn": "50.0.1",
"express": "^4.17.1",
"fast-glob": "^3.2.12",
"hash-sum": "^2.0.0",
Expand Down
12 changes: 9 additions & 3 deletions packages/client/src/TRPCClientError.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { DefaultErrorShape } from '@trpc/server';
import { TRPCErrorResponse } from '@trpc/server/rpc';
import { inferErrorShape, TRPCInferrable } from '@trpc/server/shared';
import {
getCauseFromUnknown,
inferErrorShape,
TRPCInferrable,
} from '@trpc/server/shared';
import { Maybe } from '@trpc/server/unstableInternalsExport';
import { isObject } from './internals/isObject';

Expand Down Expand Up @@ -36,7 +40,9 @@ export class TRPCClientError<TRouterOrProcedure extends TRPCInferrable>
extends Error
implements TRPCClientErrorBase<inferErrorShape<TRouterOrProcedure>>
{
public readonly cause;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore override doesn't work in all environments due to "This member cannot have an 'override' modifier because it is not declared in the base class 'Error'"
public override readonly cause;
public readonly shape: Maybe<inferErrorShape<TRouterOrProcedure>>;
public readonly data: Maybe<inferErrorShape<TRouterOrProcedure>['data']>;

Expand Down Expand Up @@ -101,7 +107,7 @@ export class TRPCClientError<TRouterOrProcedure extends TRPCInferrable>

return new TRPCClientError(cause.message, {
...opts,
cause,
cause: getCauseFromUnknown(cause),
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class SliceStream extends Transform {
super();
}

_transform(chunk: any, _: BufferEncoding, done: TransformCallback): void {
override _transform(
chunk: any,
_: BufferEncoding,
done: TransformCallback,
): void {
this.indexOffset += chunk.length;

if (!this.emitUp && this.indexOffset >= this.startIndex) {
Expand Down
37 changes: 4 additions & 33 deletions packages/server/src/error/TRPCError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TRPC_ERROR_CODE_KEY } from '../rpc/codes';
import { isObject } from './utils';
import { getCauseFromUnknown } from '../shared/getCauseFromUnknown';

export function getTRPCErrorFromUnknown(cause: unknown): TRPCError {
if (cause instanceof TRPCError) {
Expand All @@ -23,39 +23,10 @@ export function getTRPCErrorFromUnknown(cause: unknown): TRPCError {
return trpcError;
}

class UnknownCauseError extends Error {
[key: string]: unknown;
}

function getCauseFromUnknown(cause: unknown): Error | undefined {
if (cause instanceof Error) {
return cause;
}

const type = typeof cause;
if (type === 'undefined' || type === 'function' || cause === null) {
return undefined;
}

// Primitive types just get wrapped in an error
if (type !== 'object') {
return new Error(String(cause));
}

// If it's an object, we'll create a synthetic error
if (isObject(cause)) {
const err = new UnknownCauseError();
for (const key in cause) {
err[key] = cause[key];
}
return err;
}

return undefined;
}

export class TRPCError extends Error {
public readonly cause?: Error;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore override doesn't work in all environments due to "This member cannot have an 'override' modifier because it is not declared in the base class 'Error'"
public override readonly cause?: Error;
public readonly code;

constructor(opts: {
Expand Down
31 changes: 31 additions & 0 deletions packages/server/src/shared/getCauseFromUnknown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { isObject } from '../error/utils';

class UnknownCauseError extends Error {
[key: string]: unknown;
}
export function getCauseFromUnknown(cause: unknown): Error | undefined {
if (cause instanceof Error) {
return cause;
}

const type = typeof cause;
if (type === 'undefined' || type === 'function' || cause === null) {
return undefined;
}

// Primitive types just get wrapped in an error
if (type !== 'object') {
return new Error(String(cause));
}

// If it's an object, we'll create a synthetic error
if (isObject(cause)) {
const err = new UnknownCauseError();
for (const key in cause) {
err[key] = cause[key];
}
return err;
}

return undefined;
}
1 change: 1 addition & 0 deletions packages/server/src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export type { SerializeObject, Serialize } from './internal/serialize';
export { getErrorShape } from './getErrorShape';

export * from './types';
export { getCauseFromUnknown } from './getCauseFromUnknown';
Loading

0 comments on commit e6670f6

Please sign in to comment.