Skip to content

Commit fd60b3d

Browse files
export error types too
1 parent 72336dc commit fd60b3d

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

examples/bindings.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
// My custom header
22
// This file was generated by [rspc](https://github.com/specta-rs/rspc). Do not edit this file manually.
33

4+
export type Error = { type: "Mistake"; error: string } | { type: "Validator"; error: any } | { type: "Authorization"; error: string }
5+
46
export type ProceduresLegacy = { queries: { key: "cached"; input: null; result: number } | { key: "newstuff"; input: null; result: string } | { key: "newstuff2"; input: null; result: string } | { key: "newstuffpanic"; input: null; result: null } | { key: "newstuffser"; input: null; result: null } | { key: "sendMsg"; input: string; result: string } | { key: "sfmPost"; input: [string, null]; result: string } | { key: "streamInStreamInStreamInStream"; input: null; result: number } | { key: "validator"; input: { mail: string }; result: null } | { key: "withoutBaseProcedure"; input: string; result: null }; mutations: never; subscriptions: never }
57

68
export type Procedures = {
7-
cached: { kind: "query", input: null, output: number, error: unknown },
8-
newstuff: { kind: "query", input: null, output: string, error: unknown },
9-
newstuff2: { kind: "query", input: null, output: string, error: unknown },
10-
newstuffpanic: { kind: "query", input: null, output: null, error: unknown },
11-
newstuffser: { kind: "query", input: null, output: null, error: unknown },
12-
sendMsg: { kind: "query", input: string, output: string, error: unknown },
13-
sfmPost: { kind: "query", input: [string, null], output: string, error: unknown },
14-
streamInStreamInStreamInStream: { kind: "query", input: null, output: number, error: unknown },
15-
validator: { kind: "query", input: { mail: string }, output: null, error: unknown },
16-
withoutBaseProcedure: { kind: "query", input: string, output: null, error: unknown },
9+
cached: { kind: "query", input: null, output: number, error: Error },
10+
newstuff: { kind: "query", input: null, output: string, error: Error },
11+
newstuff2: { kind: "query", input: null, output: string, error: Error },
12+
newstuffpanic: { kind: "query", input: null, output: null, error: Error },
13+
newstuffser: { kind: "query", input: null, output: null, error: Error },
14+
sendMsg: { kind: "query", input: string, output: string, error: Error },
15+
sfmPost: { kind: "query", input: [string, null], output: string, error: Error },
16+
streamInStreamInStreamInStream: { kind: "query", input: null, output: number, error: Error },
17+
validator: { kind: "query", input: { mail: string }, output: null, error: Error },
18+
withoutBaseProcedure: { kind: "query", input: string, output: null, error: Error },
1719
}

examples/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum DeserializationError {
4141
}
4242

4343
#[derive(Debug, Error, Serialize, Type)]
44-
#[serde(tag = "type")]
44+
#[serde(tag = "type", content = "error")]
4545
pub enum Error {
4646
#[error("you made a mistake: {0}")]
4747
Mistake(String),

rspc/src/procedure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::{borrow::Cow, marker::PhantomData, panic::Location, sync::Arc};
3030

3131
use futures_util::{FutureExt, TryStreamExt};
3232

33-
use specta::datatype::DataType;
33+
use specta::{datatype::DataType, Generics, Type};
3434

3535
use crate::{Error, Extension, ProcedureKind, State};
3636

@@ -113,7 +113,7 @@ impl<TCtx, TInput, TOutput> Procedure<TCtx, TInput, TOutput> {
113113
location,
114114
input: TInput::data_type(types),
115115
output: TOutput::data_type(types),
116-
error: DataType::Unknown, // TODO: TError::data_type(types),
116+
error: <TError as Type>::reference(types, &[]).inner,
117117
},
118118
)
119119
}),

0 commit comments

Comments
 (0)