diff --git a/sdks/ts/packages/golem-ts-sdk/src/decorators/agent.ts b/sdks/ts/packages/golem-ts-sdk/src/decorators/agent.ts index c70a4d6c3a..820db63a38 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/decorators/agent.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/decorators/agent.ts @@ -298,7 +298,7 @@ export function agent(options?: AgentDecoratorOptions) { const agentConfigEntries = Either.getOrThrowWith( getAgentConfigEntries(classMetadata.constructorArgs), - (err) => new Error(`Failed to describe agent config: ${err}`), + (err) => new Error(`Failed to describe config for agent \`${agentTypeName.value}\`: ${err}`), ); const agentType: AgentType = { @@ -434,7 +434,9 @@ function getAgentConfigEntries( TypeScope.object(param.name, prop.path.at(-1)!, prop.type.optional), ); if (Either.isLeft(witTypeEither)) { - return Either.left(`config property \`${prop.path.join('.')}\`: ${witTypeEither.val}`); + return Either.left( + `parameter \`${param.name}\`, config property \`${prop.path.join('.')}\`: ${witTypeEither.val}`, + ); } const configSource: AgentConfigSource = prop.secret ? 'secret' : 'local'; diff --git a/sdks/ts/packages/golem-ts-sdk/src/internal/clientGeneration.ts b/sdks/ts/packages/golem-ts-sdk/src/internal/clientGeneration.ts index 13ef901dfc..8084ad69e8 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/internal/clientGeneration.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/internal/clientGeneration.ts @@ -530,7 +530,9 @@ function serializeRpcConfigObject( const result: TypedAgentConfigValue[] = []; if (rpcValue === null || typeof rpcValue !== 'object') { - throw new Error('rpcValue must be an object'); + throw new Error( + `Expected an object for config parameter \`${configProperties[0]?.path[0] ?? 'config'}\`, got ${typeof rpcValue}`, + ); } for (const prop of configProperties) { @@ -563,7 +565,10 @@ function serializeRpcConfigObject( const [witType, analysedType] = Either.getOrThrowWith( WitType.fromTsType(expectedType, undefined), - (err) => new Error(`Failed to construct analysed type for rpc agent config: ${err}`), + (err) => + new Error( + `Failed to construct type for rpc config property \`${prop.path.join('.')}\`: ${err}`, + ), ); const witValue = WitValue.fromTsValueDefault(current, analysedType); diff --git a/sdks/ts/packages/golem-ts-sdk/src/internal/mapping/types/handlers.ts b/sdks/ts/packages/golem-ts-sdk/src/internal/mapping/types/handlers.ts index 2624e7163d..739f0e65b1 100644 --- a/sdks/ts/packages/golem-ts-sdk/src/internal/mapping/types/handlers.ts +++ b/sdks/ts/packages/golem-ts-sdk/src/internal/mapping/types/handlers.ts @@ -81,7 +81,7 @@ const handlers: { [K in TsType['kind']]: Handler } = { others: handleOthers, 'unresolved-type': handleUnresolved, array: handleArray, - config: unsupportedWithHint('Config', 'Use a plain type literal instead.'), + config: unsupportedWithHint('Config', 'Use an inline object type instead.'), principal: handlePrincipal, 'quota-token': handleQuotaToken, }; diff --git a/sdks/ts/packages/golem-ts-sdk/tests/invalid.agents.test.ts b/sdks/ts/packages/golem-ts-sdk/tests/invalid.agents.test.ts index b4fa2552cc..cc3f685c08 100644 --- a/sdks/ts/packages/golem-ts-sdk/tests/invalid.agents.test.ts +++ b/sdks/ts/packages/golem-ts-sdk/tests/invalid.agents.test.ts @@ -303,7 +303,7 @@ test('Agent with unsupported type in config field is rejected with path in error await expect(async () => { await import('./agentWithInvalidConfig'); }).rejects.toThrowError( - 'Failed to describe agent config: config property `unsupported`: Unsupported type `class` in config for parameter `unsupported`. Hint: Use object instead.', + 'Failed to describe config for agent `AgentWithInvalidConfig`: parameter `config`, config property `unsupported`: Unsupported type `class` in config for parameter `unsupported`. Hint: Use object instead.', ); }); @@ -319,7 +319,7 @@ test('Config type used as a field inside another Config produces a helpful error expect(Either.isLeft(result)).toBe(true); assert(Either.isLeft(result)); expect(result.val).toBe( - 'Unsupported type `Config` in myConfig for parameter `nested`. Hint: Use a plain type literal instead.', + 'Unsupported type `Config` in myConfig for parameter `nested`. Hint: Use an inline object type instead.', ); }); diff --git a/sdks/ts/packages/golem-ts-typegen/src/index.ts b/sdks/ts/packages/golem-ts-typegen/src/index.ts index 2c7d982b1a..86766ea02b 100644 --- a/sdks/ts/packages/golem-ts-typegen/src/index.ts +++ b/sdks/ts/packages/golem-ts-typegen/src/index.ts @@ -152,11 +152,11 @@ function getTypeFromTsMorphInternal( const typeLiteral = resolveStrictTypeLiteralNode(innerType); if (typeLiteral == null) - throw `Config type parameter must be a plain type literal (e.g. Config<{ key: string }>), got: ${innerType.getText()}`; + throw `Config type parameter must be an inline object type (e.g. Config<{ key: string }>), got: ${innerType.getText()}`; const result = extractConfigPropertiesFromTypeLiteral(typeLiteral, [], wellKnownTypes); if (result == null) - throw 'Config type literal must only contain property signatures. Method signatures and index signatures are not supported.'; + throw 'Config must be an object type with only property signatures. Method signatures and index signatures are not supported.'; return { kind: 'config',